1个回答
展开全部
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
final class p extends Frame {
final static private Dimension SIZE = new Dimension(800, 600);
public String getTitle() {return "p";}
public Dimension getPreferredSize() {return SIZE;}
public Dimension getMinimumSize() {return SIZE;}
public Dimension getMaximumSize() {return SIZE;}
public Dimension getSize() {return SIZE;}
private Panel panel;
p() throws HeadlessException {
init();
attachListeners();
doLay();
setVisible(true);
}
private void init() {
panel=new Panel(){
public Dimension getPreferredSize() {
return new Dimension(100,233);
}
public void paint(Graphics g) {
super.paint(g);
Graphics g2=g.create();
g2.setColor(Color.RED);
g2.drawLine(0,0,getWidth(), 0);
g2.drawLine(0,getHeight()-2,getWidth()-2, getHeight()-2);
g2.drawLine(0,0,0,getHeight());
g2.drawLine(getWidth()-2,0,getWidth()-2,getHeight()-2);
g2.dispose();
}
};
panel.setBounds(44,44,111,222);
}
private void attachListeners() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(1);
}
});
}
private void doLay() {
setLayout(null);
add(panel);
pack();
}
public static void main(String... args) {
System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
SwingUtilities.invokeLater(p::new);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询