import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagLayout;import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;import cn.com.zhangjia.GUI.control.JATextListener;public class TestJTextArea extends JTextArea {
JTextArea abox = new JTextArea(12,12);
JTextArea aabox = new JTextArea(12,12);
JButton btn = new JButton();
JScrollPane jp = new JScrollPane() ;
JPanel panel = new JPanel();
public TestJTextArea(String title){
super(title);
initFrame();
}
private void initFrame(){
this.setSize(300, 300
Dimension dimension = this.getToolkit().getScreenSize
int height = (dimension.height - this.getHeight())/2;
int width = (dimension.width - this.getWidth())/2;
this.setLocation(width, height);
GridBagLayout layout = new GridBagLayout ();
addJA(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
} public void addJA(JPanel panel){
add(aabox);
add(abox);
add(btn);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestJTextArea("s");
}}
我怎么没有任何输出结果?要怎么改?
import java.awt.Dimension;
import java.awt.GridBagLayout;import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;import cn.com.zhangjia.GUI.control.JATextListener;public class TestJTextArea extends JTextArea {
JTextArea abox = new JTextArea(12,12);
JTextArea aabox = new JTextArea(12,12);
JButton btn = new JButton();
JScrollPane jp = new JScrollPane() ;
JPanel panel = new JPanel();
public TestJTextArea(String title){
super(title);
initFrame();
}
private void initFrame(){
this.setSize(300, 300
Dimension dimension = this.getToolkit().getScreenSize
int height = (dimension.height - this.getHeight())/2;
int width = (dimension.width - this.getWidth())/2;
this.setLocation(width, height);
GridBagLayout layout = new GridBagLayout ();
addJA(panel);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
} public void addJA(JPanel panel){
add(aabox);
add(abox);
add(btn);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new TestJTextArea("s");
}}
我怎么没有任何输出结果?要怎么改?
......
}
试试
public class TestJTextArea extends JFrame{
...
//你可以在这里设置panel的布局,如在括号里加 new GridLayout(3,1,10,10)
JPanel panel=new JPanel();
...
private void initFrame(){
this.setSize(300, 300 );
Dimension dimension = this.getToolkit().getScreenSize ;
int height = (dimension.height - this.getHeight())/2;
int width = (dimension.width - this.getWidth())/2;
this.setLocation(width, height);
//不知道你这句有什么作用,好像你在下面都没有用到layout
GridBagLayout layout = new GridBagLayout ();
this.add(panel);
addJA();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
} public void addJA(){
panel.add(aabox);
panel.add(abox);
panel.add(btn);
}
...
}
...
//你可以在这里设置panel的布局,如在括号里加 new GridLayout(3,1,10,10)
JPanel panel=new JPanel();
...
private void initFrame(){
this.setSize(300, 300 );
Dimension dimension = this.getToolkit().getScreenSize ;
int height = (dimension.height - this.getHeight())/2;
int width = (dimension.width - this.getWidth())/2;
this.setLocation(width, height);
//不知道你这句有什么作用,好像你在下面都没有用到layout
GridBagLayout layout = new GridBagLayout ();
this.add(panel);
addJA();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
} public void addJA(){
panel.add(aabox);
panel.add(abox);
panel.add(btn);
}
...
}