Jump to content


Adding A Toolkit


  • Please log in to reply
No replies to this topic

#1 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 17 February 2011 - 08:35 PM

In a window I want to display a set of buttons at the bottoms of the screen.  I tried to accomplish this by putting the three buttons in a toolkit then displaying the toolkit in a BorderLayout.south .  I do not get an error, the toolkit or the buttons simply don't show up.  Anyone know what I am doing wrong?

Here is the main window code:
	import javax.swing.*;
	import java.awt.*;
	import java.awt.event.*;
 public class FlashCardsMain extends JFrame{
 	JPanel everything;
 	SouthButtons southButtons;
 	public FlashCardsMain(){
 		super("Flash Cards");

		southButtons = new SouthButtons();

		everything = new JPanel();
		everything.setLayout(new BorderLayout());
		everything.add( southButtons, BorderLayout.SOUTH);

		setContentPane(everything);
 		setSize(300,200);
 		setLocation(50,50);
 		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 		setVisible(true);


 	}
	public static void main(String[] args){
		FlashCardsMain main = new FlashCardsMain();
	}
 }

Here is the code that contains the info about the buttons I tried to display:  
 public class SouthButtons extends JPanel{
 	FlashCardDeck cardDeck;
	JToolBar toolbox; // the toolbox that will hold the buttons
	JButton backButton; // the button that will go to the previous school
	JButton flipButton; // the button that will show the reverse side of the card
	JButton nextButton; // the button that will go to the next card

	public SouthButtons(){
		backButton = new JButton();
		backButton.addActionListener(new BackButton()); // add actionlistener to backButton
		backButton.setVisible(true);

		flipButton = new JButton();
		flipButton.addActionListener(new FlipButton()); // add actionlistener to flipButton
		flipButton.setVisible(true);

		nextButton = new JButton();
		nextButton.addActionListener(new NextButton()); // add actionlistener to nextButton
		nextButton.setVisible(true);

		toolbox = new JToolBar("Flashcard control"); // add the buttons to the toolbox
		toolbox.add(backButton);
		toolbox.add(flipButton);
		toolbox.add(nextButton);
		toolbox.setVisible(true);
	}
	private class BackButton implements ActionListener{
		public void actionPerformed(ActionEvent evt){
			cardDeck.currentCard--; // go to the previous card
		}
	}
	private class FlipButton implements ActionListener{
		public void actionPerformed(ActionEvent evt){
			if(cardDeck.viewingSide1) cardDeck.viewingSide1 = false; // flip the card
			else cardDeck.viewingSide1 = true;
		}
	}
	private class NextButton implements ActionListener{
		public void actionPerformed(ActionEvent evt){
			cardDeck.currentCard++; // go to the next card
		}
	}
 }