Ansichten: QuotePaste - CodePaste - NoPaste
Codesnippet eingetragen am 26.6.2013 um 17:18
Von: Michael
Sprache: Java
Beschreibung:
CodeSnippet:
  1. package Blatt5;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.text.DateFormat;
  6. import java.util.Calendar;
  7. import java.util.GregorianCalendar;
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JOptionPane;
  12.  
  13. /**
  14.  *
  15.  * @author skiba1
  16.  */
  17. public class GUI {
  18.  
  19. private static JLabel label1, label2;
  20. private static JButton button1, button2, button3;
  21. private static JFrame myFrame;
  22.  
  23. public static void main(String args[]) {
  24. myFrame = new JFrame("CIP-Übung 5");
  25. myFrame.setLayout(null);
  26. myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27. myFrame.setBounds(0, 0, 300, 250);
  28.  
  29. label1 = new JLabel("Bitte auswählen: ");
  30. label1.setBounds(0, 0, 300, 15);
  31.  
  32.  
  33. button1 = new JButton("Aktuelles Datum");
  34. button1.setBounds(50, 20, 200, 20);
  35. button1.addActionListener(new ButtonListener());
  36.  
  37. button2 = new JButton("Aktuelle Uhrzeit");
  38. button2.setBounds(50, 40, 200, 20);
  39. button2.addActionListener(new ButtonListener());
  40.  
  41. button3 = new JButton("Semester?");
  42. button3.setBounds(50, 60, 200, 20);
  43. button3.addActionListener(new ButtonListener());
  44.  
  45. label2 = new JLabel();
  46. label2.setBounds(10, 80, 180, 150);
  47. label2.setText("Giant Placeholder");
  48.  
  49. myFrame.add(label1);
  50. myFrame.add(label2);
  51. myFrame.add(button1);
  52. myFrame.add(button2);
  53. myFrame.add(button3);
  54. myFrame.setVisible(true);
  55. }
  56.  
  57. private static class ButtonListener implements ActionListener {
  58.  
  59.  
  60. @Override
  61. public void actionPerformed(ActionEvent e) {
  62. if (e.getSource() == button1) {
  63.  
  64. DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
  65. label2.setText(df.format(now.getTime()));
  66.  
  67. } else if (e.getSource() == button2) {
  68. DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
  69. label2.setText(df.format(now.getTime()));
  70.  
  71. } else if (e.getSource() == button3) {
  72. int year = now.get(Calendar.YEAR);
  73. int month = now.get(Calendar.MONTH);
  74.  
  75. if(month >= Calendar.APRIL && month < Calendar.OCTOBER){
  76. label2.setText("Sommersemester " + year);
  77. }else{
  78. if(month < Calendar.APRIL){
  79. label2.setText("Wintersemester " + (year-1) +"/" + year);
  80. }else{
  81. label2.setText("Wintersemester " + year +"/" + (year+1));
  82. }
  83. }
  84. // JOptionPane.showMessageDialog(myFrame, "Aus Kostengründen ist diese Funktion noch nicht implementiert", "Wir wollen mehr Geld!!! :-)", JOptionPane.INFORMATION_MESSAGE);
  85. }
  86. }
  87. }
  88. }
  89.