2015-10-15 16 views
0

我是一名專業PHP開發人員,也是一名學生。所以我有一個問題要問我在Java中持續進行的大學項目。Jframe內部列表,它將帶您到其詳細視圖

首先讓我解釋一下我所處的情況,我正在使用JDBC在Java Swing中創建一個獨立應用程序。該項目與網站類似。該項目將有四個模塊(超級用戶,公司,員工,&項目)。

當應用程序啓動時,用戶將看到登錄頁面。

Login Page

如果用戶沒有註冊,他/她可以通過點擊註冊按鈕進行註冊。

有兩種類型的用戶「1」管理員和「2」員工。

管理員可以選擇在成功登錄後轉到主頁的管理員。

但員工只能訪問前端。

Front End Page

所以我需要所有項目的列表。我也能做到這一點

但我的問題是,當用戶點擊該項目中的按鈕上市

這當然會從數據庫中動態生成!

有着各自不同的ID

?是否有可能看到項目的細節。就像在網站??

非常感謝您爲我的問題提供寶貴的時刻! 我會非常感謝任何幫助,我被困在這個問題上的時間超過了 6天。我試過搜索每一個在互聯網上,我找不到 任何答案。

希望你們將幫助

+0

*「所以我有一個問題要問我正在進行學院項目在Java中。」 *是隨機大寫單詞是很難讀,像試圖聽一會兒嘟嘟someone someone的人,然後發出聲音。請在句子的開頭使用大寫字母,單詞I以及專用名稱,如'ArrayList'或Oracle,但不能使用其他名稱。 –

+0

當我再問另一個問題時,我會記住這一點。謝謝 –

回答

0

是否有可能看到一個項目的細節。就像在網站

是的。基本上,如果您使用類似BorderLayout的東西,則可以將JList放置到WEST的位置,並將詳細面板放置到CENTER的位置。

當一個項目被選中,你可以填寫詳細信息查看與您想在看看How to use ListsHow to use BorderLayouts爲出發點

0

沒有人回答顯示

開始的數據是我正在尋找! 我已經完成了該項目,並在這裏就是答案

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 
     } 
+0

帶有自定義渲染器來顯示POJO的JList會更簡單 – MadProgrammer

相關問題