Eclipse使用SWT程序示例

import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;

public class HelloWorld extends JFrame {

public static void main(String[] args) {

HelloWorld H = new HelloWorld();

H.setVisible(true);

// JOptionPane.showMessageDialog(H, "Printing complete");

}

private JLabel jLabel;

private JTextField jTextField;

private JButton jButton;

private JComboBox jComboBox;

private JPasswordField jPasswordField;

private JCheckBox jCheckBox1;

private JCheckBox jCheckBox2;

private JRadioButton jRadioButton1;

private JRadioButton jRadioButton2;

private JTable jTable;

private JButton jButton2;

public HelloWorld() {

super();

this.setSize(600, 400);

this.getContentPane().setLayout(null);

this.add(getJLabel(), null);

this.add(getJTextField(), null);

this.add(getJButton(), null);

this.add(getJButton2(), null);

this.add(getJComboBox(), null);

this.add(getJPasswordField(), null);

this.add(getJCheckBox1(), null);

this.add(getJCheckBox2(), null);

this.add(getJRadioButton1(), null);

this.add(getJRadioButton2(), null);

this.add(getJTable(), null);

this.setTitle("HelloWorld");

}

private javax.swing.JTable getJTable() {

if (jTable == null) {

jTable = new javax.swing.JTable();

jTable.setBounds(80, 170, 160, 200);

}

return jTable;

}

private javax.swing.JRadioButton getJRadioButton1() {

if (jRadioButton1 == null) {

jRadioButton1 = new javax.swing.JRadioButton("C");

jRadioButton1.setBounds(80, 150, 160, 20);

}

return jRadioButton1;

}

private javax.swing.JRadioButton getJRadioButton2() {

if (jRadioButton2 == null) {

jRadioButton2 = new javax.swing.JRadioButton("C");

jRadioButton2.setBounds(80, 170, 160, 20);

}

return jRadioButton2;

}

private javax.swing.JCheckBox getJCheckBox2() {

if (jCheckBox2 == null) {

jCheckBox2 = new javax.swing.JCheckBox("A");

jCheckBox2.setBounds(400, 110, 160, 20);

jCheckBox2.setMnemonic('A');

}

return jCheckBox2;

}

private javax.swing.JCheckBox getJCheckBox1() {

if (jCheckBox1 == null) {

jCheckBox1 = new javax.swing.JCheckBox("B");

jCheckBox1.setBounds(400, 90, 160, 20);

jCheckBox1.setMnemonic('A');

}

return jCheckBox1;

}

private javax.swing.JPasswordField getJPasswordField() {

if (jPasswordField == null) {

jPasswordField = new javax.swing.JPasswordField();

jPasswordField.setBounds(400, 70, 160, 20);

jPasswordField.setEchoChar('*');

}

return jPasswordField;

}

private javax.swing.JComboBox getJComboBox() {

if (jComboBox == null) {

jComboBox = new javax.swing.JComboBox();

jComboBox.setBounds(400, 49, 160, 20);

jComboBox.addItem('A');

jComboBox.addItem('B');

}

return jComboBox;

}

private javax.swing.JLabel getJLabel() {

if (jLabel == null) {

jLabel = new javax.swing.JLabel();

jLabel.setBounds(34, 49, 53, 18);

jLabel.setText("Name:");

}

return jLabel;

}

private javax.swing.JTextField getJTextField() {

if (jTextField == null) {

jTextField = new javax.swing.JTextField();

jTextField.setBounds(96, 49, 160, 20);

}

return jTextField;

}

private javax.swing.JButton getJButton() {

if (jButton == null) {

jButton = new javax.swing.JButton();

jButton.setBounds(103, 110, 71, 27);

jButton.setText("OK");

jButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try {

jTextField.setText("a");

JOptionPane.showMessageDialog(jTextField.getParent(),

"Printing complete");

} catch (Exception ee) {

// TODO: handle exception

jTextField.setText(ee.toString());

}

}

});

}

return jButton;

}

private javax.swing.JButton getJButton2() {

if (jButton2 == null) {

jButton2 = new javax.swing.JButton();

jButton2.setBounds(200, 110, 71, 27);

jButton2.setText("QUIT");

jButton2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try {

System.exit(0);

} catch (Exception ee) {

// TODO: handle exception

jTextField.setText(ee.toString());

}

}

});

}

return jButton2;

}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值