fork download
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. public class Main extends JFrame {
  5.  
  6. public Main() {
  7. setTitle("Simple Car Drawing");
  8. setSize(400, 300);
  9. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  10. setLocationRelativeTo(null); // center the window
  11. }
  12.  
  13. @Override
  14. public void paint(Graphics g) {
  15. super.paint(g);
  16.  
  17. // Draw the body of the car
  18. g.setColor(Color.RED);
  19. g.fillRect(100, 100, 200, 50); // x, y, width, height
  20.  
  21. // Draw the top of the car
  22. g.setColor(Color.RED);
  23. g.fillRect(140, 70, 120, 40);
  24.  
  25. // Draw the wheels
  26. g.setColor(Color.BLACK);
  27. g.fillOval(120, 140, 40, 40);
  28. g.fillOval(240, 140, 40, 40);
  29.  
  30. // Add windows
  31. g.setColor(Color.CYAN);
  32. g.fillRect(150, 80, 40, 30);
  33. g.fillRect(210, 80, 40, 30);
  34. }
  35.  
  36. public static void main(String[] args) {
  37. SwingUtilities.invokeLater(() -> {
  38. new Main().setVisible(true);
  39. });
  40. }
  41. }
  42.  
Success #stdin #stdout #stderr 0.36s 65048KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
	at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:197)
	at java.desktop/java.awt.Window.<init>(Window.java:538)
	at java.desktop/java.awt.Frame.<init>(Frame.java:423)
	at java.desktop/java.awt.Frame.<init>(Frame.java:388)
	at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)
	at Main.<init>(Main.java:6)
	at Main.lambda$main$0(Main.java:38)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:389)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)