Guest User

Untitled

a guest
Apr 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. package components;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.util.ArrayList;
  6.  
  7. import javax.swing.*;
  8.  
  9. public class JMenuExercise extends JFrame implements ActionListener {
  10.  
  11. JFrame frame = new JFrame();
  12. JMenuBar menuBar = new JMenuBar();
  13. javax.swing.JMenu menu = new javax.swing.JMenu("Menu");
  14. JMenuItem addStudent = new JMenuItem("Add Student");
  15. JMenuItem addClub = new JMenuItem("Add Club");
  16. JMenuItem printInfo = new JMenuItem("Print Info");
  17. JPanel addStudentFrame = new JPanel();
  18. JPanel addClubFrame = new JPanel();
  19. JPanel printInfoFrame = new JPanel();
  20. JTextField textArea = new JTextField(" ");
  21. JButton submitStudent = new JButton("Submit");
  22. JButton submitClub = new JButton("Submit");
  23. ArrayList Students = new ArrayList();
  24. ArrayList Clubs = new ArrayList();
  25.  
  26. public JMenuExercise() {
  27. menuBar.add(menu);
  28. menu.setLayout(new GridLayout(2,2,2,2));
  29. menu.add(addStudent);
  30. menu.add(addClub);
  31. menu.add(printInfo);
  32.  
  33.  
  34.  
  35. addStudentFrame.setLayout(new GridLayout(2, 2, 20, 20));
  36. addStudentFrame.add(textArea);
  37. addStudentFrame.add(submitStudent);
  38.  
  39. addClubFrame.setLayout(new GridLayout(2, 3, 20, 20));
  40. addClubFrame.add(textArea);
  41. addClubFrame.add(submitClub);
  42.  
  43. printInfo.add(textArea);
  44.  
  45. frame.setJMenuBar(menuBar);
  46.  
  47. getContentPane().add(menuBar, BorderLayout.NORTH);
  48. getContentPane().add(addStudentFrame,BorderLayout.NORTH);
  49. this.setSize(400, 400);
  50.  
  51. submitStudent.addActionListener(this);
  52. submitClub.addActionListener(this);
  53. addStudent.addActionListener(this);
  54. addClub.addActionListener(this);
  55. printInfo.addActionListener(this);
  56.  
  57. }
  58.  
  59. public static void main(String[] args) {
  60. JMenuExercise mainFrame = new JMenuExercise();
  61. mainFrame.setVisible(true);
  62.  
  63. }
  64.  
  65. public void actionPerformed(ActionEvent e) {
  66. if (e.getSource() == submitStudent) {
  67. System.out.println("Pressed1");
  68. }
  69. if (e.getSource() == submitClub) {
  70. System.out.println("Pressed2");
  71. }
  72.  
  73. if (e.getSource() == addStudent) {
  74. System.out.println("Pressed3");
  75. }
  76. if (e.getSource() == addClub) {
  77. System.out.println("Pressed4");
  78.  
  79. }
  80. if (e.getSource() == printInfo) {
  81. System.out.println("Pressed5");
  82. }
  83. }
  84. }
Add Comment
Please, Sign In to add comment