58,454
社区成员
发帖
与我相关
我的任务
分享
panel.setBorder(BorderFactory.createEmptyBorder(20,20, 20, 20));
panel.setLayout(null);
panel.setVisible(true);//窗口可见
panel.setSize(500, 400);
txtIPaddress=new JTextField("localhost");
txtPort=new JTextField("3306");
txtdbName=new JTextField("databasename");
txtuserName=new JTextField();
txtpassword=new JTextField();
panel.add(lblIPaddress);
lblIPaddress.setBounds(50, 10, 50, 30);
panel.add(txtIPaddress);
txtIPaddress.setBounds(150, 10, 150, 30);
panel.add(lblPort);
lblPort.setBounds(50, 50, 50, 30);
panel.add(txtPort);
txtPort.setBounds(150, 50, 150, 30);
panel.add(lbldbName);
lbldbName.setBounds(50, 90, 60, 30);
panel.add(txtdbName);
txtdbName.setBounds(150, 90, 150, 30);
panel.add(lbluserName);
lbluserName.setBounds(50, 130, 60, 30);
panel.add(txtuserName);
txtuserName.setBounds(150, 130, 150, 30);
panel.add(lblPassword);
lblPassword.setBounds(50, 170, 60, 30);
panel.add(txtpassword);
txtpassword.setBounds(150, 170, 150, 30);
btnConfirm.setEnabled(false);//初始化时确定不可用,连接测试成功后方可以确定
panel.add(btntext);
panel.add(btnConfirm);
btntext.setBounds(320, 170, 60, 30);
btnConfirm.setBounds(400, 170, 60, 30);
panel.add(rdo_mysql);
panel.add(rdo_sqlserver);
panel.add(rdo_oracle);
rdo_mysql.setBounds(50, 250, 80, 30);
rdo_sqlserver.setBounds(150, 250, 80, 30);
rdo_oracle.setBounds(280, 250, 80, 30);
buttongroup=new ButtonGroup();
buttongroup.add(this.rdo_mysql);
buttongroup.add(this.rdo_sqlserver);
buttongroup.add(this.rdo_oracle);
import java.awt.event.*;
import javax.swing.*;
public class NoLayoutExample extends JFrame {
public NoLayoutExample(String name) {
super(name);
JTextField newItemField;
JList itemsList;
JButton addButton;
JButton removeButton;
getContentPane().setLayout(null);
//The text field
newItemField = new JTextField();
newItemField.setLocation(12,12);
newItemField.setSize(150,30);
getContentPane().add(newItemField);
//The Add button
addButton = new JButton("Add");
addButton.setMnemonic('A');
addButton.setLocation(174, 12);
addButton.setSize(100,30);
getContentPane().add(addButton);
//The List
itemsList = new JList();
JScrollPane scrollPane = new JScrollPane(itemsList,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setLocation(12,45);
scrollPane.setSize(150,150);
getContentPane().add(scrollPane);
//The Remove button
removeButton = new JButton("Remove");
removeButton.setMnemonic('R');
removeButton.setLocation(174,45);
removeButton.setSize(100,30);
getContentPane().add(removeButton);
}
public static void main(String[] args) {
JFrame frame = new NoLayoutExample("NULL Example");
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(286, 230);
frame.setResizable(false);
frame.setVisible(true);
}
}