fork download
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Rectangle;
  7.  
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10. import javax.swing.SwingUtilities;
  11.  
  12. @SuppressWarnings("serial")
  13. public class Gui extends JFrame {
  14.  
  15. public Gui() {
  16. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  17. Scene scene = new Scene(300, 300, new Quad(50, 50, 100, 100, Color.ORANGE));
  18. getContentPane().add(scene, BorderLayout.CENTER);
  19. pack();
  20. setLocationRelativeTo(null);
  21. }
  22.  
  23. public class Quad extends Rectangle {
  24. private Color color;
  25.  
  26. public Quad(int x, int y, int width, int height, Color color) {
  27. super(x, y, width, height);
  28. this.color = color;
  29. }
  30.  
  31. public Color getColor() {
  32. return color;
  33. }
  34.  
  35. }
  36.  
  37. public class Scene extends JPanel {
  38. private Quad quad;
  39.  
  40. public Scene(int width, int height, Quad quad) {
  41. super(new BorderLayout());
  42. setPreferredSize(new Dimension(width, height));
  43. this.quad = quad;
  44. }
  45.  
  46. @Override
  47. protected void paintComponent(Graphics g) {
  48. g2.setPaint(quad.getColor());
  49. g2.fill(quad);
  50. }
  51. }
  52.  
  53. public static void main(String[] args) {
  54. SwingUtilities.invokeLater(new Runnable() {
  55.  
  56. @Override
  57. public void run() {
  58. new Gui().setVisible(true);
  59. }
  60. });
  61. }
  62. }
  63.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:13: error: class Gui is public, should be declared in a file named Gui.java
public class Gui extends JFrame {
       ^
1 error
stdout
Standard output is empty