做出来的窗口上的组件显示不出来,但是用鼠标改变一下窗口的大小后组件就出来了,我是要刷新父窗口吗,还是什么,求解
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;public class CADTest extends JFrame {
JPanel doPanel;
JLabel x1,x2,x3,y1,y2,y3,xx1,xx2,xx3,yy1,yy2,yy3,original,changed,symmetry,title;
JTextField fx1,fx2,fx3,fy1,fy2,fy3,fxx1,fxx2,fxx3,fyy1,fyy2,fyy3,enlargeNum,rotationNum;
JButton enter,symmetryX,symmetryY,symmetryO,enlarge,rotation;
GridBagLayout layout;
GridBagConstraints constraints;
public CADTest() {
setTitle("CADTest");
setBounds(100,100,700,565);
//setResizable(false);
setVisible(true);
doPanel = new JPanel();
fx1 = new JTextField(3);
fx2 = new JTextField(3);
fx3 = new JTextField(3);
fy1 = new JTextField(3);
fy2 = new JTextField(3);
fy3 = new JTextField(3);
fxx1 = new JTextField(3);
fxx2 = new JTextField(3);
fxx3 = new JTextField(3);
fyy1 = new JTextField(3);
fyy2 = new JTextField(3);
fyy3 = new JTextField(3);
enlargeNum = new JTextField(7);
rotationNum = new JTextField(7);
x1 = new JLabel("x1");
x2 = new JLabel("x2");
x3 = new JLabel("x3");
y1 = new JLabel("y1");
y2 = new JLabel("y2");
y3 = new JLabel("y3");
xx1 = new JLabel("x1");
xx2 = new JLabel("x2");
xx3 = new JLabel("x3");
yy1 = new JLabel("y1");
yy2 = new JLabel("y2");
yy3 = new JLabel("y3");
original = new JLabel("原始的坐标");
changed = new JLabel("改变后的坐标");
symmetry = new JLabel("对称变换");
title = new JLabel("CDA");
enter = new JButton("确定");
symmetryX = new JButton("沿X对称");
symmetryY = new JButton("沿Y对称");
symmetryO = new JButton("沿原点对称");
enlarge = new JButton("放大倍数");
rotation = new JButton("旋转角度");
layout = new GridBagLayout();
constraints = new GridBagConstraints();
doPanel.setLayout(layout);
//doPanel.setBorder(null);
constraints.fill = GridBagConstraints.VERTICAL;
addComponent(title,0,0,14,1);
addComponent(original,1,0,1,1);
addComponent(x1,1,1,1,1);
addComponent(fx1,1,2,1,1);
addComponent(x2,1,3,1,1);
addComponent(fx2,1,4,1,1);
addComponent(x3,1,5,1,1);
addComponent(fx3,1,6,1,1);
addComponent(y1,1,7,1,1);
addComponent(fy1,1,8,1,1);
addComponent(y2,1,9,1,1);
addComponent(fy2,1,10,1,1);
addComponent(y3,1,11,1,1);
addComponent(fy3,1,12,1,1);
addComponent(enter,1,14,1,1);
addComponent(changed,2,0,1,1);
addComponent(xx1,2,1,1,1);
addComponent(fxx1,2,2,1,1);
addComponent(xx2,2,3,1,1);
addComponent(fxx2,2,4,1,1);
addComponent(xx3,2,5,1,1);
addComponent(fxx3,2,6,1,1);
addComponent(yy1,2,7,1,1);
addComponent(fyy1,2,8,1,1);
addComponent(yy2,2,9,1,1);
addComponent(fyy2,2,10,1,1);
addComponent(yy3,2,11,1,1);
addComponent(fyy3,2,12,1,1);
addComponent(symmetry,3,0,1,1);
addComponent(symmetryX,3,1,1,1);
addComponent(symmetryY,3,2,1,1);
addComponent(symmetryO,3,3,1,1);
addComponent(enlarge,4,0,1,1);
addComponent(enlargeNum,4,1,1,1);
addComponent(rotation,4,2,1,1);
addComponent(rotationNum,4,3,1,1);
doPanel.setBounds(0,0,700,130);
add(doPanel);
MyPanel p = new MyPanel();
p.setBounds(0,165,700,400);
add(p);
//his.update(this.getGraphics());
}
private void addComponent(Component component,int row,int column,int width,int height){
constraints.gridx = column;
constraints.gridy = row;
constraints.gridwidth = width;
constraints.gridheight = height;
layout.setConstraints(component, constraints);
doPanel.add(component);
}
public static void main(String[]args){
CADTest application = new CADTest();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
g.drawLine(0, 165, 700, 165);
g.drawLine(0, 365, 700, 365);
g.drawLine(350, 165, 350, 565);
}
}
}
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;public class CADTest extends JFrame {
JPanel doPanel;
JLabel x1,x2,x3,y1,y2,y3,xx1,xx2,xx3,yy1,yy2,yy3,original,changed,symmetry,title;
JTextField fx1,fx2,fx3,fy1,fy2,fy3,fxx1,fxx2,fxx3,fyy1,fyy2,fyy3,enlargeNum,rotationNum;
JButton enter,symmetryX,symmetryY,symmetryO,enlarge,rotation;
GridBagLayout layout;
GridBagConstraints constraints;
public CADTest() {
setTitle("CADTest");
setBounds(100,100,700,565);
//setResizable(false);
setVisible(true);
doPanel = new JPanel();
fx1 = new JTextField(3);
fx2 = new JTextField(3);
fx3 = new JTextField(3);
fy1 = new JTextField(3);
fy2 = new JTextField(3);
fy3 = new JTextField(3);
fxx1 = new JTextField(3);
fxx2 = new JTextField(3);
fxx3 = new JTextField(3);
fyy1 = new JTextField(3);
fyy2 = new JTextField(3);
fyy3 = new JTextField(3);
enlargeNum = new JTextField(7);
rotationNum = new JTextField(7);
x1 = new JLabel("x1");
x2 = new JLabel("x2");
x3 = new JLabel("x3");
y1 = new JLabel("y1");
y2 = new JLabel("y2");
y3 = new JLabel("y3");
xx1 = new JLabel("x1");
xx2 = new JLabel("x2");
xx3 = new JLabel("x3");
yy1 = new JLabel("y1");
yy2 = new JLabel("y2");
yy3 = new JLabel("y3");
original = new JLabel("原始的坐标");
changed = new JLabel("改变后的坐标");
symmetry = new JLabel("对称变换");
title = new JLabel("CDA");
enter = new JButton("确定");
symmetryX = new JButton("沿X对称");
symmetryY = new JButton("沿Y对称");
symmetryO = new JButton("沿原点对称");
enlarge = new JButton("放大倍数");
rotation = new JButton("旋转角度");
layout = new GridBagLayout();
constraints = new GridBagConstraints();
doPanel.setLayout(layout);
//doPanel.setBorder(null);
constraints.fill = GridBagConstraints.VERTICAL;
addComponent(title,0,0,14,1);
addComponent(original,1,0,1,1);
addComponent(x1,1,1,1,1);
addComponent(fx1,1,2,1,1);
addComponent(x2,1,3,1,1);
addComponent(fx2,1,4,1,1);
addComponent(x3,1,5,1,1);
addComponent(fx3,1,6,1,1);
addComponent(y1,1,7,1,1);
addComponent(fy1,1,8,1,1);
addComponent(y2,1,9,1,1);
addComponent(fy2,1,10,1,1);
addComponent(y3,1,11,1,1);
addComponent(fy3,1,12,1,1);
addComponent(enter,1,14,1,1);
addComponent(changed,2,0,1,1);
addComponent(xx1,2,1,1,1);
addComponent(fxx1,2,2,1,1);
addComponent(xx2,2,3,1,1);
addComponent(fxx2,2,4,1,1);
addComponent(xx3,2,5,1,1);
addComponent(fxx3,2,6,1,1);
addComponent(yy1,2,7,1,1);
addComponent(fyy1,2,8,1,1);
addComponent(yy2,2,9,1,1);
addComponent(fyy2,2,10,1,1);
addComponent(yy3,2,11,1,1);
addComponent(fyy3,2,12,1,1);
addComponent(symmetry,3,0,1,1);
addComponent(symmetryX,3,1,1,1);
addComponent(symmetryY,3,2,1,1);
addComponent(symmetryO,3,3,1,1);
addComponent(enlarge,4,0,1,1);
addComponent(enlargeNum,4,1,1,1);
addComponent(rotation,4,2,1,1);
addComponent(rotationNum,4,3,1,1);
doPanel.setBounds(0,0,700,130);
add(doPanel);
MyPanel p = new MyPanel();
p.setBounds(0,165,700,400);
add(p);
//his.update(this.getGraphics());
}
private void addComponent(Component component,int row,int column,int width,int height){
constraints.gridx = column;
constraints.gridy = row;
constraints.gridwidth = width;
constraints.gridheight = height;
layout.setConstraints(component, constraints);
doPanel.add(component);
}
public static void main(String[]args){
CADTest application = new CADTest();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
g.drawLine(0, 165, 700, 165);
g.drawLine(0, 365, 700, 365);
g.drawLine(350, 165, 350, 565);
}
}
}
解决方案 »
- MyEclipse 注册问题
- 一个JSP文件,我想在运行时,打印出当前的文件名,怎么办
- 请教有关java IO
- 求2的126次方
- 一个还没入门的人对JMSN的问题(第二次发贴,如果解决,两个贴子分数全给)
- 关于ANT的命令行执行
- 怎樣點擊 .class 文件就可以運行, 就向 .exe 文件一樣
- 晕~~,WinXP居然装不了JBuilder7,Win2000下都可以啊!
- JAVA能访问WINDOWS注册表吗?有例程吗?
- 下载了jive创建论坛后出现不能正常发表一篇文章字数在100-200之间的帖子????
- 请问怎样能实现图文混排的发送,就像QQ那样,先从本机里面找出一张图片,放在聊天框里,然后输入文字,按发送,一起发给对方,对方也能收到图片和文字
- JAVA关于窗口和按钮的多次反复添加实现
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;public class CADTest extends JFrame { JPanel doPanel;
JLabel x1, x2, x3, y1, y2, y3, xx1, xx2, xx3, yy1, yy2, yy3, original, changed, symmetry, title;
JTextField fx1, fx2, fx3, fy1, fy2, fy3, fxx1, fxx2, fxx3, fyy1, fyy2, fyy3, enlargeNum, rotationNum;
JButton enter, symmetryX, symmetryY, symmetryO, enlarge, rotation;
GridBagLayout layout;
GridBagConstraints constraints; public CADTest() {
setTitle("CADTest");
doPanel = new JPanel();
fx1 = new JTextField(3);
fx2 = new JTextField(3);
fx3 = new JTextField(3);
fy1 = new JTextField(3);
fy2 = new JTextField(3);
fy3 = new JTextField(3);
fxx1 = new JTextField(3);
fxx2 = new JTextField(3);
fxx3 = new JTextField(3);
fyy1 = new JTextField(3);
fyy2 = new JTextField(3);
fyy3 = new JTextField(3);
enlargeNum = new JTextField(7);
rotationNum = new JTextField(7);
x1 = new JLabel("x1");
x2 = new JLabel("x2");
x3 = new JLabel("x3");
y1 = new JLabel("y1");
y2 = new JLabel("y2");
y3 = new JLabel("y3");
xx1 = new JLabel("x1");
xx2 = new JLabel("x2");
xx3 = new JLabel("x3");
yy1 = new JLabel("y1");
yy2 = new JLabel("y2");
yy3 = new JLabel("y3");
original = new JLabel("原始的坐标");
changed = new JLabel("改变后的坐标");
symmetry = new JLabel("对称变换");
title = new JLabel("CDA");
enter = new JButton("确定");
symmetryX = new JButton("沿X对称");
symmetryY = new JButton("沿Y对称");
symmetryO = new JButton("沿原点对称");
enlarge = new JButton("放大倍数");
rotation = new JButton("旋转角度");
layout = new GridBagLayout();
constraints = new GridBagConstraints();
doPanel.setLayout(layout);
constraints.fill = GridBagConstraints.VERTICAL;
addComponent(title, 0, 0, 14, 1);
addComponent(original, 1, 0, 1, 1);
addComponent(x1, 1, 1, 1, 1);
addComponent(fx1, 1, 2, 1, 1);
addComponent(x2, 1, 3, 1, 1);
addComponent(fx2, 1, 4, 1, 1);
addComponent(x3, 1, 5, 1, 1);
addComponent(fx3, 1, 6, 1, 1);
addComponent(y1, 1, 7, 1, 1);
addComponent(fy1, 1, 8, 1, 1);
addComponent(y2, 1, 9, 1, 1);
addComponent(fy2, 1, 10, 1, 1);
addComponent(y3, 1, 11, 1, 1);
addComponent(fy3, 1, 12, 1, 1);
addComponent(enter, 1, 14, 1, 1);
addComponent(changed, 2, 0, 1, 1);
addComponent(xx1, 2, 1, 1, 1);
addComponent(fxx1, 2, 2, 1, 1);
addComponent(xx2, 2, 3, 1, 1);
addComponent(fxx2, 2, 4, 1, 1);
addComponent(xx3, 2, 5, 1, 1);
addComponent(fxx3, 2, 6, 1, 1);
addComponent(yy1, 2, 7, 1, 1);
addComponent(fyy1, 2, 8, 1, 1);
addComponent(yy2, 2, 9, 1, 1);
addComponent(fyy2, 2, 10, 1, 1);
addComponent(yy3, 2, 11, 1, 1);
addComponent(fyy3, 2, 12, 1, 1);
addComponent(symmetry, 3, 0, 1, 1);
addComponent(symmetryX, 3, 1, 1, 1);
addComponent(symmetryY, 3, 2, 1, 1);
addComponent(symmetryO, 3, 3, 1, 1);
addComponent(enlarge, 4, 0, 1, 1);
addComponent(enlargeNum, 4, 1, 1, 1);
addComponent(rotation, 4, 2, 1, 1);
addComponent(rotationNum, 4, 3, 1, 1);
doPanel.setBounds(0, 0, 700, 130);
add(doPanel);
MyPanel p = new MyPanel();
p.setBounds(0, 165, 700, 400);
add(p);
setSize(700, 565);
} private void addComponent(Component component, int row, int column, int width, int height) {
constraints.gridx = column;
constraints.gridy = row;
constraints.gridwidth = width;
constraints.gridheight = height;
layout.setConstraints(component, constraints);
doPanel.add(component);
} public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() { @Override
public void run() {
CADTest application = new CADTest();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.setLocationRelativeTo(null);
application.setVisible(true);
}
});
} class MyPanel extends JPanel { @Override
public void paintComponent(Graphics g) {
g.drawLine(0, 165, 700, 165);
g.drawLine(0, 365, 700, 365);
g.drawLine(350, 165, 350, 565);
}
}
}