import java.awt.*;
import javax.swing.*;public class MyComponent extends JComponent{
Panel pane; public void addComponentsToPane() {
Panel pane = new Panel();pane.setVisible(true);
Panel p1, p2 ;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
p1 = new Panel ();p1.setBackground(Color.pink); p1.setVisible(true); c.gridx = 0; c.gridy = 0;
c.weightx = 1;c.weighty = 1;
c.ipadx= 0;c.ipady=0;c.fill = GridBagConstraints.BOTH;
pane.add(p1, c); p2= new Panel ();p2.setBackground(Color.red); p2.setVisible(true);
c.gridx = 3; c.gridy = 0;
c.weightx = 0.3;c.weighty = 0.3;
c.ipadx= 0;c.ipady=0; pane.add(p2, c);
}
MyComponent(){
super(); addComponentsToPane() ;
setVisible(true);
}
public static void main (String args[]) {
JFrame f = new JFrame();
MyComponent mc = new MyComponent();
f.getContentPane().add(mc);f.setVisible(true);
}
}
import javax.swing.*;public class MyComponent extends JComponent{
Panel pane; public void addComponentsToPane() {
Panel pane = new Panel();pane.setVisible(true);
Panel p1, p2 ;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
p1 = new Panel ();p1.setBackground(Color.pink); p1.setVisible(true); c.gridx = 0; c.gridy = 0;
c.weightx = 1;c.weighty = 1;
c.ipadx= 0;c.ipady=0;c.fill = GridBagConstraints.BOTH;
pane.add(p1, c); p2= new Panel ();p2.setBackground(Color.red); p2.setVisible(true);
c.gridx = 3; c.gridy = 0;
c.weightx = 0.3;c.weighty = 0.3;
c.ipadx= 0;c.ipady=0; pane.add(p2, c);
}
MyComponent(){
super(); addComponentsToPane() ;
setVisible(true);
}
public static void main (String args[]) {
JFrame f = new JFrame();
MyComponent mc = new MyComponent();
f.getContentPane().add(mc);f.setVisible(true);
}
}
解决方案 »
- Excel2007和2003解析操作的方法,作为程序员一定要掌握
- 一个很简单问题(如何把\转为/)
- StringBuffer问题
- java当中如何发送一个http或者asp的请求
- 怎样求出前天的日期?
- 如何计算两个java.util.data类之间的差
- 同志们,请问throws和try-catch块的区别?
- 我想试试我的msn(hotmail登录的那个聊天软件)是否能用,但是没有再线的其他用户!那为朋友能提供一个那我测试一下?
- JBuilder初学者,帮我推荐几本比较好的书,好吗?(最好能具体点儿,谢谢 ~~~)
- 为什么每次更改单元格颜色,上次更改的内容无法保存,并且怎么实现对之前单元格颜色更改的恢复?
- 求jarsync示例代码
- 动态编译问题
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame();
MyComponent mc = new MyComponent();
f.getContentPane().add(mc);
f.setVisible(true);
}
});
}
import javax.swing.*;public class MyComponent extends JComponent {
Panel pane; public void addComponentsToPane() {
Panel pane = new Panel();
pane.setVisible(true);
Panel p1, p2;
pane.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
p1 = new Panel();
p1.setBackground(Color.pink);
p1.setVisible(true); c.gridx = 0;
c.gridy = 0;
c.weightx = 1;
c.weighty = 1; c.ipadx = 0;
c.ipady = 0;
c.fill = GridBagConstraints.BOTH;
pane.add(p1, c); p2 = new Panel();
p2.setBackground(Color.red);
p2.setVisible(true); c.gridx = 3;
c.gridy = 0;
c.weightx = 0.3;
c.weighty = 0.3;
c.ipadx = 0;
c.ipady = 0; pane.add(p2, c); } MyComponent() {
super();
addComponentsToPane(); setVisible(true);
} public static void main(String args[]) {
JFrame f = new JFrame();
MyComponent mc = new MyComponent();
f.getContentPane().add(mc);
f.setBounds(100,200,400,500);//没有设定大小。。
f.setVisible(true);
}
}
JFrame f = new JFrame();
MyComponent mc = new MyComponent();
f.getContentPane().add(mc);
f.setSize(400,500);//没有设定大小。。
f.setVisible(true);
}
这句没用,好像还要重写什么方法的