Home > Back-end >  Homework: write a Java application as required (hope bosses more help, emergency)
Homework: write a Java application as required (hope bosses more help, emergency)

Time:09-22

Menu design and event: (1) including commodity management, commodity increases, commodity change, goods to delete, dividing line, commodity query; Settings: red, yellow, green, (2) query menu click commodity, jump to the new framework, click a different color, frame color

CodePudding user response:

refer to the original poster weixin_46053515 response:
menu design and event: (1) including commodity management: commodity increases, commodity change, goods to delete, dividing line, commodity query; Setting: red, yellow, green, (2) query menu click on the commodity, jump to the new framework, click on the different color, frame color


 
Public class TestFrame extends JFrame implements ActionListener {
TestFrame () {
SetSize (480, 300);
JMenuBar jb=new JMenuBar ();
JMenu jmenu1=new JMenu (" commodity management ");
JMenuItem jitem1=new JMenuItem (" commodity increase ");
JMenuItem jitem2=new JMenuItem (" goods to modify ");
JMenuItem jitem3=new JMenuItem (delete "goods");
JMenuItem jitem4=new JMenuItem (" query goods ");
Jmenu1. Add (jitem1);
Jmenu1. Add (jitem2);
Jmenu1. Add (jitem3);
Jmenu1. AddSeparator ();
Jmenu1. Add (jitem4);
JMenu jmenu2=new JMenu (" set ");
JMenuItem jitem5=new JMenuItem (" red ");
JMenuItem jitem6=new JMenuItem (" yellow ");
JMenuItem jitem7=new JMenuItem (" green ");
Jmenu2. Add (jitem5);
Jmenu2. Add (jitem6);
Jmenu2. Add (jitem7);
Jb. The add (jmenu1);
Jb. The add (jmenu2);
Jitem4. AddActionListener (this);
Jitem5. AddActionListener (this);
Jitem6. AddActionListener (this);
Jitem7. AddActionListener (this);
SetJMenuBar (jb);
SetDefaultCloseOperation (DISPOSE_ON_CLOSE);
setVisible(true);
}

Public static void main (String [] args) {
New TestFrame ();
}

@ Override
Public void actionPerformed (an ActionEvent e) {
//TODO Auto - generated method stub
System. The out. Println (um participant etActionCommand ());
If (um participant etActionCommand (.) the equals (" commodity query ")) {
New GueryFrame ();
} else if (um participant etActionCommand (.) the equals (" red ")) {
GetContentPane (). SetBackground (Color red);
Repaint ();
} else if (um participant etActionCommand (.) the equals (" yellow ")) {
GetContentPane (). SetBackground (Color yellow);
Repaint ();
} else if (um participant etActionCommand (.) the equals (" green ")) {
GetContentPane (). SetBackground (Color. Green);
Repaint ();
}

}

}


 
Public class GueryFrame extends JFrame {

GueryFrame () {
SetSize (480, 300);
SetTitle (" query goods ");
SetDefaultCloseOperation (DISPOSE_ON_CLOSE);
setVisible(true);
}

}

CodePudding user response:

Thank you for your big help
  • Related