用java自行编写程序实现如图的布局,对按钮不必加行动监视器。
1个回答
展开全部
这个简单 ,我给你拖出来了。
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
//VS4E -- DO NOT REMOVE THIS LINE!
public class Test extends JFrame {
private static final long serialVersionUID = 1L;
private JTextField jTextField3;
private JLabel jLabel0;
private JLabel jLabel1;
private JLabel jLabel2;
private JLabel jLabel3;
private JTextField jTextField1;
private JTextField jTextField2;
private JTextField jTextField0;
private JLabel jLabel4;
private JButton jButton1;
private JButton jButton0;
private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
public Test() {
initComponents();
}
private void initComponents() {
setLayout(new GroupLayout());
add(getJLabel0(), new Constraints(new Leading(30, 60, 10, 10), new Leading(25, 10, 10)));
add(getJLabel1(), new Constraints(new Leading(30, 60, 12, 12), new Leading(63, 10, 10)));
add(getJLabel2(), new Constraints(new Leading(30, 57, 10, 10), new Leading(102, 10, 10)));
add(getJLabel3(), new Constraints(new Leading(30, 53, 10, 10), new Leading(140, 10, 10)));
add(getJTextField1(), new Constraints(new Leading(111, 168, 10, 10), new Leading(61, 12, 12)));
add(getJTextField3(), new Constraints(new Leading(111, 168, 12, 12), new Leading(140, 12, 12)));
add(getJTextField2(), new Constraints(new Leading(111, 168, 12, 12), new Leading(101, 12, 12)));
add(getJTextField0(), new Constraints(new Leading(113, 164, 12, 12), new Leading(27, 12, 12)));
add(getJLabel4(), new Constraints(new Leading(97, 129, 10, 10), new Leading(176, 12, 12)));
add(getJButton1(), new Constraints(new Leading(177, 10, 10), new Leading(206, 12, 12)));
add(getJButton0(), new Constraints(new Leading(77, 10, 10), new Leading(206, 12, 12)));
setSize(320, 257);
}
private JButton getJButton0() {
if (jButton0 == null) {
jButton0 = new JButton();
jButton0.setText("清除");
}
return jButton0;
}
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setText("确认");
}
return jButton1;
}
private JLabel getJLabel4() {
if (jLabel4 == null) {
jLabel4 = new JLabel();
jLabel4.setText("创建表成功!");
}
return jLabel4;
}
private JTextField getJTextField0() {
if (jTextField0 == null) {
jTextField0 = new JTextField();
jTextField0.setText("表名");
}
return jTextField0;
}
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
jTextField2.setText("Name char(15)");
}
return jTextField2;
}
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setText("ID char(10)");
}
return jTextField1;
}
private JLabel getJLabel3() {
if (jLabel3 == null) {
jLabel3 = new JLabel();
jLabel3.setText("字段3");
}
return jLabel3;
}
private JLabel getJLabel2() {
if (jLabel2 == null) {
jLabel2 = new JLabel();
jLabel2.setText("字段2");
}
return jLabel2;
}
private JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new JLabel();
jLabel1.setText("字段1");
}
return jLabel1;
}
private JLabel getJLabel0() {
if (jLabel0 == null) {
jLabel0 = new JLabel();
jLabel0.setText("表名");
}
return jLabel0;
}
private JTextField getJTextField3() {
if (jTextField3 == null) {
jTextField3 = new JTextField();
jTextField3.setText("Score integer");
}
return jTextField3;
}
private static void installLnF() {
try {
String lnfClassname = PREFERRED_LOOK_AND_FEEL;
if (lnfClassname == null)
lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lnfClassname);
} catch (Exception e) {
System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
+ " on this platform:" + e.getMessage());
}
}
/**
* Main entry of the class.
* Note: This class is only created so that you can easily preview the result at runtime.
* It is not expected to be managed by the designer.
* You can modify it as you like.
*/
public static void main(String[] args) {
installLnF();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Test frame = new Test();
frame.setDefaultCloseOperation(Test.EXIT_ON_CLOSE);
frame.setTitle("生成数据表");
frame.getContentPane().setPreferredSize(frame.getSize());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询