读入数据小界面(修改4-成功)

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


class Face1 extends JFrame implements ActionListener{
/**

*/
private static final long serialVersionUID = -4310787077706275381L;
JFrame f;
JPanel panel1, panel2, panel3;
JTextField tf1, tf2;
JLabel label1, label2, label3 ;
Button bt;

public Face1(){
f = new JFrame();
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();

tf1 = new JTextField(10);
tf2 = new JTextField(10);

label1 = new JLabel("您想输入的数据有:");
label2 = new JLabel("行");
label3 = new JLabel("列");
bt = new Button("Enter");
bt.addActionListener(this);

f.setLayout(new BorderLayout());
panel1.setLayout(new BorderLayout());
panel2.setLayout(new BorderLayout());
panel3.setLayout(new BorderLayout());

panel1.add(label1, "West"); //??
panel2.add(tf1, "West");
panel2.add(label2, "Center");
panel3.add(tf2, "West");
panel3.add(label3, "Center");
panel3.add(bt, "East");

//panel1.setSize(300,100);
//panel2.setSize(300,100);
//panel3.setSize(300,100); //用来调窗口大小


f.add(panel1, "North");
f.add(panel2, "Center");
f.add(panel3, "South");

f.setTitle("Face1");
f.setBounds(600, 300, 500, 500); //后面两个参数貌似没用?
f.pack();
f.setVisible(true);


}

public void actionPerformed(ActionEvent e) {
int line = 0, row = 0;
line = Integer.parseInt(tf1.getText());
row =Integer.parseInt(tf2.getText());

Face2 face2 = new Face2(line,row);
face2.init();
}

}

class Face2 extends JFrame{
int line = 0, row = 0;
public Face2(int line,int row){ 
this.line = line;
this.row =row;
}

public void init(){ //一定要有这个方法 之前没有有很大的错误!!!
JFrame f = new JFrame(); 
JLabel label = new JLabel("请输入数据:");

JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();

JTextField[][] tf = new JTextField[line][row];

f.setLayout(new BorderLayout());
panel2.setLayout(new GridLayout(line,row)); //将panel2分为line行,row列,注意与GridBagLayout区别

panel1.add(label);
for(int i = 0; i < line; i++)
for(int j = 0; j < row; row++){    //row++  改为j++!!!!   错误提示:超出内存 
tf[i][j] = new JTextField(10);
panel2.add(tf[i][j]);
}

f.add(panel1,"North");
f.add(panel2,"South");
f.setTitle("Face2");
f.pack();
f.setVisible(true);

}


}

public class Test1{
public static void main(String args[]){
Face1 face1 = new Face1(); 
}
}










}   /*SUCCESS!!



以后如果想要输入数据  直接输入获取处理就行   需要增加处理数据的代码

问题由来:解决输入数据是否为数独问题 数据如何输入

*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值