2 Replies - 303 Views - Last Post: 07 December 2012 - 09:34 PM Rate Topic: -----

#1 heathbb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-October 12

Trying to develop a FlashCard Quiz app to help students study better

Posted 06 December 2012 - 09:58 PM

please help, I am able to create a frame window which displays two buttons, but I want the program to end when the user hits the Quit button, and I want the program to open a new window (which will display flashcards or multiple choice questions) when the user clicks begin

here is what I have so far:

Im stuck

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusListener;

public class TestImageIcon extends JFrame {

	private static ImageIcon myIcon = new ImageIcon("src/Resources/my.png");

	public TestImageIcon() {
		
		
	 // Create two buttons
		 JButton jbtOK = new JButton("Begin");
		 JButton jbtCancel = new JButton("Quit");
		
		 // Create a panel to hold buttons
		 JPanel panel = new JPanel();
		 panel.add(jbtOK);
		 panel.add(jbtCancel);
		
		 add(panel); // Add panel to the frame
		
		 // Register listeners
		
		 CancelListenerClass listener2 = new CancelListenerClass();
		
		 jbtCancel.addActionListener(listener2);
	
		
//		setLayout(new GridLayout(1, 4, 5, 5));
//	
//		//add(new JLabel(myIcon));
//		add(new JButton("Genetics FlashCard Quiz", myIcon), BorderLayout.CENTER);
//	
//		JCheckBox jchk = new JCheckBox("Begin", false);
//		jchk.setForeground(Color.BLACK);
//		jchk.setBackground(Color.LIGHT_GRAY);
//		jchk.setMnemonic('B');
//		
//		final JCheckBox jchk1 = new JCheckBox("Quit", false);
//		jchk1.setForeground(Color.BLACK);
//		jchk1.setBackground(Color.LIGHT_GRAY);
//		jchk1.setMnemonic('Q');
//		
//		
//		//This code below adds a check box
//		
//		add(jchk);
//		add(jchk1);
//		
//		//Register a listener for the check boxes
//		
//		jchk1.addActionListener(new ActionListener() {
//			
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				
//				//jchk1.
//			}});
//			
////		
//		//This code below creates a selectable bulletpoint, good for multiple choice questions.
//		
////		JRadioButton jrb1 = new JRadioButton("Student", true);
////		jrb1.setForeground(Color.RED);
////		jrb1.setBackground(Color.WHITE);
////		jrb1.setMnemonic('S');
////		
////		ButtonGroup group = new ButtonGroup();
////		add(jrb1);
////		
//		
//		
	}
	
	 class OKListenerClass implements ActionListener{
		 public void actionPerformed(ActionEvent e) {
		 System.out.println("OK button clicked");
		 }
		 }
	 
	 class CancelListenerClass implements ActionListener{
		  public void actionPerformed(ActionEvent e) {
		  System.out.println("Cancel button clicked");
		  }
		  }

	/** Main method */
	public static void main(String[] args) {
//		TestImageIcon frame = new TestImageIcon();
//		frame.pack();
//		frame.setTitle("Genetics Flashcard Quiz");
//		frame.setSize(300, 150);
//		frame.setLocationRelativeTo(null); // Center the frame
//		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		frame.setVisible(true);
//		
		
		TestImageIcon frame = new TestImageIcon();
			 frame.setTitle("Genetics FlashCard Quiz");
			 frame.setSize(300, 75);
			 frame.setLocation(200, 100);
			 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			 frame.setVisible(true);
			 }
			 
		
		
		


	}

	


Is This A Good Question/Topic? 0
  • +

Replies To: Trying to develop a FlashCard Quiz app to help students study better

#2 heathbb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-October 12

Re: Trying to develop a FlashCard Quiz app to help students study better

Posted 07 December 2012 - 09:23 AM

nump
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Trying to develop a FlashCard Quiz app to help students study better

Posted 07 December 2012 - 09:34 PM

???
What is wrong with ?
    class CancelListenerClass implements ActionListener{  
        public void actionPerformed(ActionEvent e) {  
           System.out.println("Cancel button clicked");  
           System.exit(0);  
           }  
        }  


Actually would be cleaner to pass your JFrame to the CancelListenerClass constructor
to save it as an instance variable
to dispose() it first before calling System.exit(0) when the actionPerformed() is called
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1