我在 youtube 上练习教程。在这里-> http://www.youtube.com/watch?v=QdbKQ5h9yZg&list=PL70BFBF88CE38C556
我检查了几十次下面的代码。但我仍然不明白为什么 JFrame 没有正确显示。虽然我把尺寸设置为 600x400(或大于),但是当我运行项目时仍然没有任何变化,JFrame
尺寸没有改变,标签也没有显示。问题出在哪里?
这是我的代码:
package doanjava;
import java.sql.*;
public class db {
Connection con;
Statement st;
ResultSet rs;
public db(){
connect();
}
public void connect(){
try{
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
String db = "jdbc:odbc:ketnoi";
con = DriverManager.getConnection(db);
st = con.createStatement();
String sql = "select * from HoSoSinhVien";
rs = st.executeQuery(sql);
while(rs.next())
{
String Ho = rs.getString("Ho");
String Ten = rs.getString("Ten");
String Tuoi = rs.getString("Tuoi");
String Lop = rs.getString("Lop");
String SoDienThoai = rs.getString("SoDienThoai");
String DiaChi = rs.getString("DiaChi");
System.out.println(Ho+" "+Ten+" | "+"Tuoi: "+Tuoi+" | "+"Lop :"+Lop+" | "+"SDT: "+SoDienThoai+" | "+"Dia Chi: "+DiaChi);
}
}catch(Exception ex){
}
}
public static void main(String[] args) {
new db();
new gui();
}
}
和
package doanjava;
import javax.swing.*;
public class gui {
JFrame f;
JLabel Ho;
JLabel Ten;
JLabel Tuoi;
JLabel Lop;
JTextField t;
JTextField t1;
JTextField t2;
JTextField t3;
public gui(){
frame();
}
public void frame(){
f = new JFrame();
f.setVisible(true);
f.setSize(600,400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Ho = new JLabel("Ho");
Ten = new JLabel("Ten");
Tuoi = new JLabel("Tuoi");
Lop = new JLabel("Lop");
t = new JTextField(10);
t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(10);
JPanel p = new JPanel();
p.add(Ho);
p.add(t);
p.add(Ten);
p.add(t1);
p.add(Tuoi);
p.add(t2);
p.add(Lop);
p.add(t3);
f.add(p);
}
}