62,621
社区成员
发帖
与我相关
我的任务
分享import javax.swing.*;
import java.awt.*;
public class SwingTemplate extends JPanel {
public SwingTemplate() {
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Your drawing code
g.fillRect(10, 10, 100, 100);
}
private static void createAndShowGUI() {
JFrame frame = new JFrame();
frame.setContentPane(new SwingTemplate());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}