fork download
  1. import java.awt.Button;
  2. import java.awt.GridLayout;
  3. import java.util.Date;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JLabel;
  9. import javax.swing.JPanel;
  10. import javax.swing.JTextField;
  11.  
  12. public class Datemanager {
  13.  
  14. static JTextField field1 = new JTextField(30);
  15. static JButton timeButton = new JButton("Show time");
  16. static JButton exitButton = new JButton("Exit");
  17.  
  18. public static void main (String[] args) {
  19.  
  20. JPanel windowTime = new JPanel();
  21.  
  22. GridLayout gl = new GridLayout(4, 2);
  23. windowTime.setLayout(gl);
  24.  
  25. JLabel label1 = new JLabel("Time");
  26.  
  27. windowTime.add(label1);
  28. windowTime.add(field1);
  29. windowTime.add(timeButton);
  30. windowTime.add(exitButton);
  31.  
  32. ActionListener actionListener = new DateActionListener();
  33. timeButton.addActionListener(actionListener);
  34. exitButton.addActionListener(actionListener);
  35.  
  36.  
  37.  
  38. JFrame frame =new JFrame("Time manager");
  39. frame.setContentPane(windowTime);
  40. frame.pack();
  41. frame.setVisible(true);
  42.  
  43. Datemanager dateManager =new Datemanager();
  44. }
  45.  
  46. public static class DateActionListener implements ActionListener {
  47. public void actionPerformed(ActionEvent e) {
  48. if (e.getSource() == timeButton) {
  49. Date date = new Date();
  50. field1.setText(String.valueOf(date));
  51. } else {
  52. System.exit(0);
  53. }
  54. }
  55. }
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:12: error: class Datemanager is public, should be declared in a file named Datemanager.java
public class Datemanager {
       ^
1 error
stdout
Standard output is empty