fork download
  1.  
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Graphics;
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JPanel;
  8.  
  9. public class GUI extends JFrame{
  10.  
  11. public GUI() {
  12. setTitle("Frame");
  13. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  14. add(new MainPanel());
  15. setResizable(false);
  16. pack();
  17. setVisible(true);
  18. }
  19.  
  20. public static void main(String[] args) {
  21. new GUI();
  22. }
  23. }
  24.  
  25. class MainPanel extends JPanel{
  26.  
  27. private final Dimension size = new Dimension(500, 500);
  28.  
  29. public MainPanel() {
  30.  
  31. JLabel label = new JLabel();
  32. setBackground(Color.black);
  33. label.setText("Hello World");
  34. label.setForeground(Color.green);
  35. add(label);
  36. }
  37.  
  38. @Override
  39. public void paintComponent(Graphics g) {
  40. super.paintComponent(g);
  41. g.setColor(Color.GREEN);
  42. g.drawLine(0, 250, 500, 250);
  43. }
  44.  
  45. @Override
  46. public Dimension preferredSize() {
  47. return size;
  48. }
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:9: error: class GUI is public, should be declared in a file named GUI.java
public class GUI extends JFrame{
       ^
Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
stdout
Standard output is empty