fork download
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. // Swing Program Template for running as application or Applet
  6. @SuppressWarnings("serial")
  7. public class SwingTemplateApp extends JPanel {
  8. // Name-constants to define the various dimensions
  9. public static final int WINDOW_WIDTH = 300;
  10. public static final int WINDOW_HEIGHT = 150;
  11. // ......
  12.  
  13. // private variables of UI components
  14. // ......
  15.  
  16. /** Constructor to setup the UI components */
  17. public SwingTemplateApp() {
  18. // "this" JPanel sets layout
  19. // this.setLayout(new ....Layout());
  20.  
  21. // Allocate the UI components
  22. // .....
  23.  
  24. // "this" JPanel adds components
  25. // this.add(....)
  26.  
  27. // Source object adds listener
  28. // .....
  29.  
  30. }
  31.  
  32. /** The entry main() method */
  33. public static void main(String[] args) {
  34. // Run GUI codes in the Event-Dispatching thread for thread safety
  35. SwingUtilities.invokeLater(new Runnable() {
  36. public void run() {
  37. JFrame frame = new JFrame();
  38. frame.setContentPane(new SwingTemplateApp());
  39. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40. frame.setTitle("......");
  41. frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); // or pack()
  42. frame.setVisible(true);
  43. }
  44. });
  45. }
  46. }
  47. Main Applet Class
  48. 1
  49. 2
  50. 3
  51. 4
  52. 5
  53. 6
  54. 7
  55. 8
  56. 9
  57. 10
  58. 11
  59. 12
  60. 13
  61. 14
  62. 15
  63. 16
  64. 17
  65. 18
  66. 19
  67. 20
  68. 21
  69. 22
  70. 23
  71. 24
  72. import java.lang.reflect.InvocationTargetException;
  73. import javax.swing.JApplet;
  74.  
  75. // Swing Program Template for running as Applet
  76. @SuppressWarnings("serial")
  77. public class SwingTemplateApplet extends JApplet {
  78.  
  79. /** init() to setup the UI components */
  80. @Override
  81. public void init() {
  82. // Run GUI codes in the Event-Dispatching thread for thread safety
  83. try {
  84. javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
  85. public void run() {
  86. setContentPane(new SwingTemplateApplet());
  87. }
  88. });
  89. e.printStackTrace();
  90. } catch (InterruptedException e) {
  91. e.printStackTrace();
  92. }
  93. }
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:47: error: class, interface, or enum expected
Main Applet Class
^
Main.java:73: error: class, interface, or enum expected
import javax.swing.JApplet;
^
2 errors
stdout
Standard output is empty