将类设置成static 或者将该类写在public static void main(String[] args) {。。。}外面就行
package eluosi;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class eluosi {
public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println("Hello EluoSiRect!\n");
JFrame f = new JFrame();
f.setSize(400, 300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new Mypanel());
f.setVisible(true);
}
}
class Mypanel extends JPanel{
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.setColor(new Color(0xff0000));
//g.draw3DRect(10, 10, 30, 30, true);
g.setFont(new Font("黑体",Font.BOLD,32));
g.drawString("Hello", 50, 50);
}
}