Java布局管理器使用方法探讨 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-23
);
frame1.show();
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(borderLayout1);
jPanel1.setBackground(Color.red);
jPanel1.setLayout(flowLayout1);
jPanel2.setBackground(Color.red);
jPanel2.setLayout(flowLayout2);
jPanel3.setBackground(Color.pink);
jPanel3.setLayout(gridLayout1);
jLabel1.setPreferredSize(new Dimension(100, 16));
jLabel1.setText("请输入查询条件");
jTextField1.setPreferredSize(new Dimension(140, 22));
jTextField1.setText("");
jButton1.setText("查询");
jButton1.addActionListener(new Frame1_jButton1_actionAdapter(this));
flowLayout1.setAlignment(FlowLayout.LEFT);
flowLayout1.setHgap(5);
flowLayout1.setVgap(10);
jButton2.setText("增加");
jButton3.setText("删除");
jButton4.setText("修改");
flowLayout2.setHgap(30);
flowLayout2.setVgap(5);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().add(jPanel1, BorderLayout.NORTH);
jPanel1.add(jLabel1, null);
jPanel1.add(jTextField1, null);
jPanel1.add(jButton1, null);
this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
jPanel2.add(jButton2, null);
jPanel2.add(jButton3, null);
jPanel2.add(jButton4, null);
this.getContentPane().add(jPanel3, BorderLayout.CENTER);
jPanel3.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jTable1, null);
}
//模拟查询数据库
void jButton1_actionPerformed(ActionEvent e) {
try { //制作表
Vector vcol = new Vector(); //列名
Vector vrow = new Vector(); //内容
for (int col = 1; col < 31; col++) {
vcol.addElement("列" + col);
}
for (int row = 1; row < 101; row++) {
Vector vr1 = new Vector();
for (int col = 1; col < 31; col++) {
vr1.addElement(row + "/" + col);
}
vrow.addElement(vr1);
}
DefaultTableModel dtm = new DefaultTableModel(vrow, vcol);
jTable1 = new JTable(vrow, vcol);
jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //滚动条设置左右滚
this.jScrollPane1.getViewport().add(jTable1, null); //在滚动条中放入表
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
}
class Frame1_jButton1_actionAdapter
implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_jButton1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
} |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于Java布局管理器使用方法探讨 - 编程入门网的所有评论