用JAVA怎么建立一个大小为300*200的JFrame窗体,在里面添加三个标签、两个文本框、两个按

 我来答
匿名用户
2013-08-17
展开全部
import java.awt.BorderLayout;
import java.awt.EventQueue;import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;public class T extends JFrame { private JPanel contentPane;
public JLabel lblNewLabel;
public JLabel label;
public JLabel label_1;
public JTextField textField;
public JTextField textField_1;
public JButton btnNewButton;
public JButton button; public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
T frame = new T();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

public T() {
setTitle("JFrame窗体例子");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 300, 200);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

lblNewLabel = new JLabel("帐号:");
lblNewLabel.setBounds(70, 60, 30, 21);
contentPane.add(lblNewLabel);

label = new JLabel("密码:");
label.setBounds(70, 91, 30, 21);
contentPane.add(label);

label_1 = new JLabel("图片标签");
label_1.setBounds(10, 10, 264, 40);
contentPane.add(label_1);

textField = new JTextField();
textField.setBounds(102, 60, 109, 21);
contentPane.add(textField);
textField.setColumns(10);

textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(102, 91, 109, 21);
contentPane.add(textField_1);

btnNewButton = new JButton("登录");
btnNewButton.setBounds(217, 128, 57, 24);
contentPane.add(btnNewButton);

button = new JButton("设置");
button.setBounds(10, 128, 57, 24);
contentPane.add(button);
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式