沒有人回答顯示
開始的數據是我正在尋找! 我已經完成了該項目,並在這裏就是答案
DbConnect con = null;
try { con = new DbConnect(); }
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException e) { e.printStackTrace(); }
// Retreiving Results
try {
ResultSet res = null;
res = con.selectQueryBig("select * from tbl_company where owner_id='"+User_Session.getSessionId()+"' ORDER BY id Desc");
int i=1;
if (res!= null){
while(res.next()){
//Titles
PanelDynamic[i] = new JPanel(new WrapLayout(FlowLayout.LEFT,10,0));
PanelDynamic[i].setPreferredSize(new Dimension(800,40));
if (i%2 == 0) {
PanelDynamic[i].setBackground(new Color(255,255,255,255));
} else {
PanelDynamic[i].setBackground(new Color(255,255,255,200));
}
// Name Of Company
LabelDynamic[i] = new JLabel(res.getString("name"));
LabelDynamic[i].setHorizontalAlignment(SwingConstants.LEFT);
LabelDynamic[i].setPreferredSize(new Dimension(240,40));
LabelDynamic[i].setForeground(new Color(0,0,0));
// Created date
LabelDynamicB[i] = new JLabel(res.getString("created"));
LabelDynamicB[i].setHorizontalAlignment(SwingConstants.LEFT);
LabelDynamicB[i].setPreferredSize(new Dimension(170,40));
LabelDynamicB[i].setForeground(new Color(0,0,0));
// Created date
LabelDynamicC[i] = new JLabel(res.getString("updated"));
LabelDynamicC[i].setHorizontalAlignment(SwingConstants.LEFT);
LabelDynamicC[i].setPreferredSize(new Dimension(170,40));
LabelDynamicC[i].setForeground(new Color(0,0,0));
// Button For Read More
ButtonDynamic[i] = new JButton("Edit");
ButtonDynamic[i].setHorizontalAlignment(SwingConstants.LEFT);
ButtonDynamic[i].setPreferredSize(new Dimension(100,40));
ButtonDynamic[i].setBorderPainted(false);
ButtonDynamic[i].setFocusPainted(false);
ButtonDynamic[i].setBackground(new Color(255,255,255,0));
ButtonDynamic[i].setForeground(new Color(0,0,0));
ButtonDynamic[i].setIcon(EIco);
ButtonDynamic[i].setActionCommand(Integer.toString(res.getInt("id")));
PanelDynamic[i].add(LabelDynamic[i]);// title
PanelDynamic[i].add(LabelDynamicB[i]);// Created
PanelDynamic[i].add(LabelDynamicC[i]);// Created
PanelDynamic[i].add(ButtonDynamic[i]);// Edit
panelBoxin.add(PanelDynamic[i]);
panelBoxin.revalidate();
i+=1;
}}
res.close();
ResLength = i;
}
catch (SQLException e) { e.printStackTrace(); }
// Closing Connection
try { con.release(); con.disconnect(); }
catch (SQLException e) {e.printStackTrace(); }
我們真正需要做的是,我們要動態地生成按鈕與動作命令=主鍵ID。
,我們必須寫按鈕動作在一個循環
// Dashboard Button Actions
public class ListenerForCompany implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
// Edit Button Array
for (int i=0; i< AdminViewObj.ResLength(); i++){
if(e.getSource()==AdminViewObj.ButtonDynamic[i]){
// Parsing id
Integer id =Integer.parseInt(AdminViewObj.ButtonDynamic[i].getActionCommand());
// loading screen and thread
AdminViewObj.loadingView.setVisible(true);
new Thread(new Runnable(){
@Override
public void run(){
try {
ProjectManagement.CompanyAddEditView(id);
AdminViewObj.dispose();
}
catch(Exception e) {
AdminViewObj.loadingView.setVisible(false);
AdminViewObj.ErrorMessage("Could not connect to server");
}
}
}).start();
}// end of for
}
*「所以我有一個問題要問我正在進行學院項目在Java中。」 *是隨機大寫單詞是很難讀,像試圖聽一會兒嘟嘟someone someone的人,然後發出聲音。請在句子的開頭使用大寫字母,單詞I以及專用名稱,如'ArrayList'或Oracle,但不能使用其他名稱。 –
當我再問另一個問題時,我會記住這一點。謝謝 –