fork download
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package SwingDemo;
  7.  
  8. import java.awt.Color;
  9. import java.awt.GridLayout;
  10. import java.awt.HeadlessException;
  11. import javax.swing.JFrame;
  12. import javax.swing.JLabel;
  13.  
  14. /**
  15.  *
  16.  * @author ta
  17.  */
  18. public class MyJLableWithColor extends JFrame{
  19.  
  20. public MyJLableWithColor(String title) throws HeadlessException {
  21.  
  22. this.setSize(600,800);
  23. this.getContentPane().setLayout(new GridLayout(1,2,5,5));
  24. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25. this.setLocationRelativeTo(null);
  26. this.setVisible(true);
  27.  
  28. JLabel lb1,lb2;
  29.  
  30. lb1 = CreatLable("JLabel 1", Color.yellow, Color.darkGray);
  31.  
  32. lb2 = CreatLable("JLabel 2", Color.red, Color.CYAN);
  33.  
  34.  
  35. this.getContentPane().add(lb1);
  36. this.getContentPane().add(lb2);
  37.  
  38.  
  39.  
  40.  
  41. }
  42.  
  43. private JLabel CreatLable(String text,Color textColor,Color backgroundColor) {
  44.  
  45. JLabel lb = new JLabel(text);
  46.  
  47. lb.setHorizontalTextPosition(JLabel.CENTER);
  48.  
  49. lb.setForeground(textColor);
  50.  
  51.  
  52. lb.setOpaque(true);
  53.  
  54. lb.setBackground(backgroundColor);
  55. return lb;
  56. }
  57.  
  58.  
  59. public static void main(String[] args) {
  60.  
  61. new MyJLableWithColor("MY WINDOW");
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68. }
  69.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:18: error: class MyJLableWithColor is public, should be declared in a file named MyJLableWithColor.java
public class MyJLableWithColor extends JFrame{
       ^
1 error
stdout
Standard output is empty