Question: //java programming, Joyce farrell; 8th ed //Debugging Exercises/ //CHapter 15 Advanced GUI //ouput, need to fix error 1 import javax.swing.*; 2 import java.awt.*; 3 import
//java programming, Joyce farrell; 8th ed
//Debugging Exercises/
//CHapter 15 Advanced GUI
//ouput, need to fix error
1 import javax.swing.*; 2 import java.awt.*; 3 import java.awt.event.*; 4 public class DebugFifteen4 extends JFrame 5 { 6 JMenuBar mainBar = new JMenuBar(); 7 JMenu menu1 = new JMenu("File"); 8 JMenu menu2 = new JMenu("Symbols"); 9 JMenu menu3 = new JMenu("Cities"); 10 JMenuItem exit = new JMenuItem("Exit"); 11 JMenuItem animal = new JMenuItem("Animal"); 12 JMenuItem song = new JMenuItem("Song"); 13 JMenuItem flower = new JMenuItem("Flower"); 14 JMenuItem milwaukee = new JMenuItem("Milwaukee"); 15 JMenuItem madison = new JMenuItem("Madison"); 16 JLabel label1 = new JLabel(" Wisconsin Facts "); 17 JLabel label2 = new JLabel(); 18 public DebugFifteen4() 19 { 20 setTitle("Facts about Wisconsin"); 21 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 22 setLayout(new FlowLayout()); 23 setJMenuBar(mainBar); 24 mainBar.add(menu1); 25 mainBar.add(menu2); 26 mainBar.add(menu3); 27 menu1.add(exit) 28 menu2.add(animal); 29 menu2.add(song); 30 menu2.add(flower); 31 menu3.add(Milwaukee); 32 menu3.add(Madison); 33 exit.addActionListener(this); 34 animal.addActionListener(this); 35 song.addActionListener(this); 36 flowmer.addActionListener(this); 37 milwalkee.addActionListener(this); 38 madisin.addActionListener(this); 39 add(label1); 40 label1.setFont(new Font("Arial", Font.BOLD, 14)); 41 add(label2); 42 label2.setFont(new Font("Arial", Font.PLAIN, 14)); 43 } 44 @Override 45 public void actionPerformed(ActionEvent e) 46 { 47 Object source = e.getSource(); 48 String text = " "; 49 if(source == exit) 50 System.exit(0); 51 else if(source == animal) 52 text = "The state animal is badger"; 53 else if(source == song) 54 text = "The state song is On Wisconsin!"; 55 else if(source == flower) 56 text = "The state flower is wood violet"; 57 else if(source == milwaukee) 58 text = "Milwaukee is the largest city"; 59 else 60 text = "Madison is the capitol"; 61 label2.setText(text); 62 repaint(); 63 } 64 65 public static void main(String[] args) 66 { 67 DebugFifteen4 frame = new DebugFifteen4(); 68 final int WIDTH = 250; 69 final int HEIGHT = 200; 70 frame.setSize(WIDTH, HEIGHT); 71 frame.setVisible(true); 72 } 73 } 74
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
