所以我试图在jpanel中获取一个按钮列表但是当我编译注意发生时 此按钮将根据time.getResult()类的结果更改颜色 当它假设显示不同颜色的按钮时,框架显示为空 谢谢 每件事似乎没有错误,但注意到发生 这是代码
public t5() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JPanel panel = new JPanel();
try
{
JButton[] label1 = new JButton[7];
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
String query="select * from employes";
PreparedStatement pst=con.prepareStatement(query);
ResultSet rs=pst.executeQuery();
int i=0;
while(rs.next())
{
Timer time=new Timer(rs.getString("date_de_embauche").toString());
int j=(int) time.getResulte();
if(j<=0)
{
label1[i] = new JButton(rs.getString("id")+" "+rs.getString("nom")+" "+rs.getString("prenom"));
label1[i].setForeground(Color.red);
label1[i].setPreferredSize(dim);
contentPane.add(panel);
}
if(j<=10 || j!=0)
{
label1[i] = new JButton(rs.getString("id")+" "+rs.getString("nom")+" "+rs.getString("prenom"));
label1[i].setForeground(Color.orange);
label1[i].setPreferredSize(dim);
contentPane.add(panel);
}
if(j<=15 || j!=10)
{
label1[i] = new JButton(rs.getString("id")+" "+rs.getString("nom")+" "+rs.getString("prenom"));
label1[i].setForeground(Color.yellow);
label1[i].setPreferredSize(dim);
contentPane.add(panel);
}
else
{
label1[i] = new JButton(rs.getString("id")+" "+rs.getString("nom")+" "+rs.getString("prenom"));
label1[i].setForeground(Color.black);
label1[i].setPreferredSize(dim);
contentPane.add(panel);
}
i++;
//System.out.println(rs.getString("nom")+" "+rs.getString("prenom")+" "+time.getResulte());
//System.out.println(rs.getString("date_de_embauche"));
}
}