当前位置: 代码迷 >> Eclipse >> (新手上路)怎样使用setBounds方法是添加在框架的label、textfield和按钮看起来更美观,如:解决方法
  详细解决方案

(新手上路)怎样使用setBounds方法是添加在框架的label、textfield和按钮看起来更美观,如:解决方法

热度:310   发布时间:2016-04-23 18:55:44.0
(新手上路)怎样使用setBounds方法是添加在框架的label、textfield和按钮看起来更美观,如:
package person_with_abality;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

import javax.swing.*;
public class tianjia1 extends JFrame implements ActionListener {
Label Label1=new Label("ID:");
TextField textField1=new TextField();
Label Label2=new Label("姓名:");
TextField textField2=new TextField();
Label Label3=new Label("性别:");
TextField textField3=new TextField();
Label Label4=new Label("年龄:");
TextField textField4=new TextField();
Label Label5=new Label("技能:");
TextField textField5=new TextField();
Label Label6=new Label("服务行业:");
TextField textField6=new TextField();
Label Label7=new Label("毕业院校:");
TextField textField7=new TextField();
Label Label8=new Label("备注:");
TextField textField8=new TextField();
Label Label9=new Label("入库时间:");
TextField textField9=new TextField();
Label Label10=new Label("录用情况:");
TextField textField10=new TextField();

Button button1=new Button("确定");
Button button2=new Button("取消");

Connection con;
Statement stmt;
String url;
ResultSet rs;

public tianjia1() throws Exception
{
super("人才信息添加界面");
setSize(800,600);
setLayout(null);
setBackground(new Color(110,200,150));
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int x=screenSize.width;
int y=screenSize.height;
this.setLocation((x-200)/2, (y-200)/2);

button1.setBounds(219, 228, 89, 25);
button1.addActionListener(this);
button2.setBounds(68, 226, 83, 23);
button2.addActionListener(this);

Label1.setBounds(45,86,57,19);
Label2.setBounds(45,126,57,19);
Label3.setBounds(45,170, 57, 19);
Label4.setBounds(160,86,53,19);
Label5.setBounds(160,126,57,19);
Label6.setBounds(160,170, 57, 19);
Label7.setBounds(340,86,57,19);
Label8.setBounds(340,126,57,19);
Label9.setBounds(0,170, 57, 40);
Label10.setBounds(360,170, 57, 40);

textField1.setBounds(105, 86, 76, 20);
textField2.setBounds(105, 126, 76, 20);
textField3.setBounds(105, 170, 76, 20);
textField4.setBounds(175, 86, 76, 20);
textField5.setBounds(175, 126, 76, 20);
textField6.setBounds(175, 170, 76, 20);
textField7.setBounds(271, 169, 76, 20);
textField8.setBounds(271, 86, 76, 20);
textField9.setBounds(271, 126, 76, 20);
textField10.setBounds(381, 170, 76, 20);

add(button1);
add(button2);

add(Label1);
add(Label2);
add(Label3);
add(Label4);
add(Label5);
add(Label6);
add(Label7);
add(Label8);
add(Label9);
add(Label10);

add(textField1);
add(textField2);
add(textField3);
add(textField4);
add(textField5);
add(textField6);
add(textField7);
add(textField8);
add(textField9);
add(textField10);

setVisible(true);

url="jdbc:sqlserver://localhost:1433;databaseName=Talents;user=sa;password=123;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection(url);
stmt=con.createStatement();
}
public void actionPerformed(ActionEvent e){
String str1=e.getActionCommand();
if(str1.equals("确定"))
{
if(textField2.getText().equals("")||textField1.getText().equals(""))
{
dialog3 t=new dialog3();
}
else
{
try{
rs=stmt.executeQuery("select * from IFM");
if(rs.next())
{
if(textField1.getText().equals(rs.getString("ID")))
  相关解决方案