package hello;
import java.awt.*;
import javax.swing.*;
class windows extends JFrame
{
windows()
{
JFrame J=new JFrame("表單");
J.setSize(300, 300);
//J.getContentPane().setBackground(Color.lightGray);
J.setLocation(100,100);
Container c=J.getContentPane();
c.setLayout(new FlowLayout());
c.add(new JLabel("bt"));
c.add(new JButton("a"));
J.setVisible(true);
}
}
class Panl extends JPanel
{
public void paint(Graphics p)
{
p.drawLine(100,100, 200, 200);
}
}
public class g extends JPanel {
public static void main(String[] args) {
windows w=new windows();
Panl d=new Panl();
w.add(d);
}
}
uj5u.com熱心網友回復:
你這樣設定有問題,應該先把jpanel加入jframe中,jframe設定Visible才有效,這里牽涉到畫面的重繪。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/129400.html
標籤:Java EE
上一篇:Java中沒有加鎖的方法,在當前執行緒sleep后,執行后面方法的時候會新建一條執行緒嗎,如果想在sleep后重新執行本方法,為什么一定要return
下一篇:求完數
