Guest User

Untitled

a guest
Aug 15th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. package contentframes;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.event.ItemEvent;
  8. import java.awt.event.ItemListener;
  9. import java.text.DateFormat;
  10. import java.text.SimpleDateFormat;
  11. import java.util.Date;
  12.  
  13. import javax.swing.BorderFactory;
  14. import javax.swing.JButton;
  15. import javax.swing.JDesktopPane;
  16. import javax.swing.JFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JPanel;
  19. import javax.swing.JSeparator;
  20. import javax.swing.JTextField;
  21. import javax.swing.JToggleButton;
  22. import javax.swing.SwingConstants;
  23.  
  24. public class MainMenu extends JPanel {
  25.  
  26. /**
  27. *
  28. */
  29. private static final long serialVersionUID = 3056297202012883384L;
  30. static JDesktopPane pane;
  31. static JPanel pnlDates;
  32. static JPanel test;
  33. static JPanel console;
  34. static JDesktopPane test1;
  35. private JTextField textField;
  36.  
  37. public MainMenu() {
  38. super(new BorderLayout());
  39. setBackground(Color.WHITE);
  40. // TODO set size variably!!!!111
  41. setMinimumSize(new Dimension(1170, 550));
  42. setPreferredSize(new Dimension(1170, 550));
  43. pane = new JDesktopPane();
  44. pane.setSize(1170, 550);
  45.  
  46. pnlDates = new JPanel(null);
  47. pnlDates.setPreferredSize(getMaximumSize());
  48. pnlDates.setBackground(Color.WHITE);
  49.  
  50. // Set border
  51. pnlDates.setBorder(BorderFactory.createEmptyBorder());
  52.  
  53. // Add controls to pane
  54. add(pnlDates);
  55.  
  56. // Get and Set Current Day
  57. DateFormat dateFormat = new SimpleDateFormat("dd. MMMM yyyy ");
  58. Date datetoday = new Date();
  59. dateFormat.format(datetoday);
  60. String today = dateFormat.format(datetoday);
  61.  
  62. // Set Labels and Bounds
  63. JLabel lblToday = new JLabel(today);
  64. lblToday.setFont(new Font("Tahoma", Font.BOLD, 11));
  65. lblToday.setForeground(new Color(51, 102, 153));
  66. lblToday.setHorizontalAlignment(SwingConstants.RIGHT);
  67. lblToday.setBounds(577, 13, 205, 25);
  68. pnlDates.add(lblToday);
  69.  
  70. JPanel pnlUpcoming = new JPanel();
  71. pnlUpcoming.setBackground(Color.WHITE);
  72. pnlUpcoming.setBounds(12, 45, 770, 188);
  73. pnlDates.add(pnlUpcoming);
  74. pnlUpcoming.setLayout(null);
  75.  
  76. JPanel pnlAlerts = new JPanel();
  77. pnlAlerts.setBackground(Color.WHITE);
  78. pnlAlerts.setBounds(823, 44, 343, 493);
  79. pnlDates.add(pnlAlerts);
  80.  
  81. String username = System.getProperty("user.name");
  82. JLabel lblUser = new JLabel("Willkommen " + username + " ,");
  83.  
  84. lblUser.setHorizontalAlignment(SwingConstants.LEFT);
  85. lblUser.setForeground(new Color(51, 102, 153));
  86. lblUser.setFont(new Font("Tahoma", Font.BOLD, 11));
  87. lblUser.setBounds(12, 13, 205, 25);
  88. pnlDates.add(lblUser);
  89.  
  90. final JLabel lblConsole = new JLabel("Console");
  91. lblConsole.setHorizontalAlignment(SwingConstants.LEFT);
  92. lblConsole.setForeground(new Color(51, 102, 153));
  93. lblConsole.setFont(new Font("Tahoma", Font.BOLD, 11));
  94. lblConsole.setBounds(12, 486, 205, 25);
  95. pnlDates.add(lblConsole);
  96. console = new console(true, true, "log.txt");
  97. console.setSize(770, 241);
  98. console.setLocation(12, 271);
  99.  
  100. JLabel lblHinweise = new JLabel("Hinweise:");
  101. lblHinweise.setHorizontalAlignment(SwingConstants.LEFT);
  102. lblHinweise.setForeground(new Color(51, 102, 153));
  103. lblHinweise.setFont(new Font("Tahoma", Font.BOLD, 11));
  104. lblHinweise.setBounds(823, 13, 205, 25);
  105. pnlDates.add(lblHinweise);
  106.  
  107. JSeparator separator = new JSeparator();
  108. separator.setOrientation(SwingConstants.VERTICAL);
  109. separator.setBounds(800, -45, 2, 678);
  110. pnlDates.add(separator);
  111.  
  112. textField = new JTextField();
  113. textField.setBounds(11, 515, 724, 22);
  114. pnlDates.add(textField);
  115. textField.setColumns(10);
  116.  
  117. JButton ConsoleOK = new JButton("OK");
  118. ConsoleOK.setFont(new Font("Tahoma", Font.PLAIN, 10));
  119. ConsoleOK.setBounds(735, 514, 50, 23);
  120. pnlDates.add(ConsoleOK);
  121.  
  122. final JToggleButton tglbtnV = new JToggleButton("^");
  123. tglbtnV.setFont(new Font("Tahoma", Font.PLAIN, 10));
  124.  
  125. ItemListener itemListener = new ItemListener() {
  126. public void itemStateChanged(ItemEvent itemEvent) {
  127. int state = itemEvent.getStateChange();
  128. if (state == ItemEvent.SELECTED) {
  129. System.out.println("Selected");
  130. pnlDates.add(console);
  131. tglbtnV.setText("v");
  132. lblConsole.setBounds(12, 246, 205, 25);
  133. tglbtnV.setBounds(735, 247, 47, 23);
  134. } else {
  135. System.out.println("Deselected");
  136. pnlDates.remove(console);
  137. tglbtnV.setBounds(735, 487, 47, 23);
  138. tglbtnV.setText("^");
  139. lblConsole.setBounds(12, 486, 205, 25);
  140. }
  141. }
  142. };
  143. tglbtnV.addItemListener(itemListener);
  144. tglbtnV.setBounds(735, 487, 50, 23);
  145. pnlDates.add(tglbtnV);
  146.  
  147. }
  148.  
  149. public static void main(String[] args) {
  150. JFrame frame = new JFrame();
  151. frame.add(new MainMenu());
  152. frame.setBounds(0, 0, 770, 240);
  153. System.out.println("test");
  154. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  155. frame.setVisible(true);
  156. }
  157.  
  158.  
  159. }
Add Comment
Please, Sign In to add comment