CodeSnippet:
package Blatt5; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; /** * * @author skiba1 */ public class GUI { private static JLabel label1, label2 ; private static JButton button1, button2, button3 ; private static JFrame myFrame ; public static void main (String args []) { myFrame = new JFrame("CIP-Übung 5"); myFrame.setLayout(null); myFrame. setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); myFrame.setBounds(0, 0, 300, 250); label1 = new JLabel("Bitte auswählen: "); label1.setBounds(0, 0, 300, 15); button1 = new JButton("Aktuelles Datum"); button1.setBounds(50, 20, 200, 20); button1.addActionListener(new ButtonListener()); button2 = new JButton("Aktuelle Uhrzeit"); button2.setBounds(50, 40, 200, 20); button2.addActionListener(new ButtonListener()); button3 = new JButton("Semester?"); button3.setBounds(50, 60, 200, 20); button3.addActionListener(new ButtonListener()); label2.setBounds(10, 80, 180, 150); label2.setText("Giant Placeholder"); myFrame.add(label1); myFrame.add(label2); myFrame.add(button1); myFrame.add(button2); myFrame.add(button3); myFrame.setVisible(true); } @Override if (e.getSource() == button1) { label2.setText(df.format(now.getTime())); } else if (e.getSource() == button2) { label2.setText(df.format(now.getTime())); } else if (e.getSource() == button3) { label2.setText("Sommersemester " + year); }else{ label2.setText("Wintersemester " + (year-1) +"/" + year); }else{ label2.setText("Wintersemester " + year +"/" + (year+1)); } } // JOptionPane.showMessageDialog(myFrame, "Aus Kostengründen ist diese Funktion noch nicht implementiert", "Wir wollen mehr Geld!!! :-)", JOptionPane.INFORMATION_MESSAGE); } } } }
|