很多初學者在用Java布局器自動布局畫界面時
首先
第二
第三
第四
最後
程序源代碼如下(除中文注釋部分的兩句是自己加上去
import javax
import java
import java
import java
import javax
public class Frame
extends JFrame {
BorderLayout borderLayout
JPanel jPanel
JPanel jPanel
JPanel jPanel
JLabel jLabel
JTextField jTextField
JButton jButton
FlowLayout flowLayout
FlowLayout flowLayout
JButton jButton
JButton jButton
JButton jButton
GridLayout gridLayout
JScrollPane jScrollPane
JTable jTable
public Frame
try {
jbInit()
}
catch (Exception e) {
e
}
}
public static void main(String[] args) {
Frame
frame
frame
}
private void jbInit() throws Exception {
this
jPanel
jPanel
jPanel
jPanel
jPanel
jPanel
jLabel
jLabel
jTextField
jTextField
jButton
jButton
flowLayout
flowLayout
flowLayout
jButton
jButton
jButton
flowLayout
flowLayout
this
this
jPanel
jPanel
jPanel
this
jPanel
jPanel
jPanel
this
jPanel
jScrollPane
}
//模擬查詢數據庫
void jButton
try { //制作表
Vector vcol = new Vector()
Vector vrow = new Vector()
for (int col =
vcol
}
for (int row =
Vector vr
for (int col =
vr
}
vrow
}
DefaultTableModel dtm = new DefaultTableModel(vrow
jTable
jTable
this
}
catch (Exception ex) {
JOptionPane
}
}
}
class Frame
implements java
Frame
Frame
this
}
public void actionPerformed(ActionEvent e) {
adaptee
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26584.html