Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Midterms extends JFrame implements ActionListener {
		JMenuBar b = new JMenuBar();
		
		JMenu file = new JMenu("File");
		JMenu color = new JMenu("Color");
		JMenu font = new JMenu("Size");
		
		JMenuItem neww  = new JMenuItem("New");
		JMenuItem open  = new JMenuItem("Open");
		JMenuItem save  = new JMenuItem("Save");
		
		JMenuItem red = new JMenuItem("Red");
		JMenuItem blu  = new JMenuItem("Blue");
		JMenuItem gre  = new JMenuItem("Green");
		
		JMenuItem f12 = new JMenuItem("Size 12");
		JMenuItem f14 = new JMenuItem("size 14");
		JMenuItem f16 = new JMenuItem("size 16");
		Font f = new Font ("Verdana",Font.PLAIN,20);
		
		JLabel text = new JLabel("Animo LaSalle",JLabel.CENTER);
    	Container c = getContentPane();
	public Midterms(){
		
		c.setLayout(new FlowLayout());
    	c.setLayout(new BorderLayout());
    	
    	setSize(450,300);
    	setVisible(true);
    	setTitle("Mideterm Exam");
    	setLocation(30,30);
    	setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    
    	setJMenuBar(b);
    	c.add(text);
    	
    	b.add(file);
    	b.add(color);
    	b.add(font);
    	
    	file.add(open);
    	file.add(neww);
    	file.add(save);
    	
    	color.add(red);
    	color.add(blu);
    	color.add(gre);
    	
    	font.add(f12);
    	font.add(f14);
    	font.add(f16);
    	
    	//accelerators&mnemonics
    	red.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK));
		gre.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK));
		blu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK));
		
		open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
		neww.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
		save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		
		file.setMnemonic('F');
		color.setMnemonic('C');
		font.setMnemonic('S');
		
		open.setMnemonic('O');
		neww.setMnemonic('N');
		save.setMnemonic('S');
		
		red.setMnemonic('R');
		blu.setMnemonic('B');
		gre.setMnemonic('G');
		
		//events
		red.addActionListener(this);
		blu.addActionListener(this);
		gre.addActionListener(this);
		f12.addActionListener(this);
		f14.addActionListener(this);
		f16.addActionListener(this);
	
		
	}
	@Override
	public void actionPerformed(ActionEvent e){
		
		if(e.getSource() == red)
			text.setForeground(Color.red);
			
		if(e.getSource() == gre)
			text.setForeground(Color.green);
			
		if(e.getSource() == blu)
			text.setForeground(Color.blue);
			
		if(e.getSource() == f12)
			text.setFont(new Font("Arial", Font.PLAIN, 12));
			
		if(e.getSource() == f14)
			text.setFont(new Font("Arial", Font.PLAIN, 14));
			
		if(e.getSource() == f16)
			text.setFont(new Font("Arial", Font.PLAIN, 16));
			
		
	}	
	
  	
	
		public static void main (String args[]){
					Midterms ME = new Midterms();
		}
	
	
	
	
	
}


What I have tried:

i tried overriding them but the error says error: Midterms is not abstract and does not override abstract method windowDeactivated(WindowEvent) in WindowListener.

I wan't to make a pop up message when I exit the windows but I can't. Thanks in advance guys! :)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900