洛神賦

          子虛烏有

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            7 Posts :: 10 Stories :: 0 Comments :: 0 Trackbacks

          該程序是很簡單 只是把我上一個程序可視化希望能給初學java的人提供幫助!!!

          //stock

          package StockUI;

          public class Stock {

           private int id;      // 
           private String name;  //
           private int price;  //
           private int flag;   //
           
           
           public int getId() {
            return id;
           }
           public void setId(int id) {
            this.id = id;
           }
           public String getName() {
            return name;
           }
           public void setName(String name) {
            this.name = name;
           }
           public int getPrice() {
            return price;
           }
           public void setPrice(int price) {
            this.price = price;
           }
           public int getFlag() {
            return flag;
           }
           public void setFlag(int flag) {
            this.flag = flag;
           }
           
           
          }


          //服務器端

          package StockUI;

          import java.util.Random;


          public class StockServer {

           
           public static void main(String[] args){
            
            
            Stock sk[] = getStock();
            for(int i=0;i<sk.length;i++){
             if(sk[i] != null){
              System.out.println("name = " + sk[i].getPrice());
              
             }
            }
           }
           
           
           public static Stock[] getStock(){
            
            
            Stock stock[] = new Stock[3];
           //##################################################### 
            Stock sk = new Stock();
            sk.setId(1);
            sk.setName("ibm");
            Random rd = new Random();
            sk.setPrice(rd.nextInt(100));
            sk.setFlag(1);
            stock[0] = sk;
           //#######################################################
            Stock sk1 = new Stock();
            sk1.setId(2);
            sk1.setName("sun");  
            sk1.setPrice(rd.nextInt(100));
            sk1.setFlag(1);
            stock[1] = sk1;
           //###################################################### 
            Stock sk2 = new Stock();
            sk2.setId(3);
            sk2.setName("oracle");  
            sk2.setPrice(rd.nextInt(100));
            sk2.setFlag(1);
            stock[2] = sk2;
            
            
            
            return stock;
            
           }
           
          }




          package StockUI;
           
          import org.eclipse.swt.SWT;
          import org.eclipse.swt.custom.TableEditor;
          import org.eclipse.swt.layout.FillLayout;
          import org.eclipse.swt.widgets.Display;
          import org.eclipse.swt.widgets.Event;
          import org.eclipse.swt.widgets.Listener;
          import org.eclipse.swt.widgets.Menu;
          import org.eclipse.swt.widgets.MenuItem;
          import org.eclipse.swt.widgets.MessageBox;
          import org.eclipse.swt.widgets.Shell;
          import org.eclipse.swt.widgets.Table;
          import org.eclipse.swt.widgets.TableColumn;
          import org.eclipse.swt.widgets.TableItem;

           

          public class StockUI {
           
          private TableEditor editor = null;  
          private Table table = null; 

          public static void main(String[] args) {  
             new StockUI();  
          }  
          private StockUI() {  
             Display display = new Display();  
             Shell shell = new Shell(display);  
             shell.setLayout(new FillLayout());  
             shell.setText("大智慧股票模擬系統");  
             createTable(shell,display);  
             shell.pack();       //窗口變大
             shell.open();  
             while (!shell.isDisposed()) {  
              if (!display.readAndDispatch())  
               display.sleep();  
             }  
             display.dispose();  
          }  
          /** 
          * 創建表格 
          *  
          * @param shell 
          */ 
          private void createTable(final Shell shell,final Display display) {  
             table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);  
             editor = new TableEditor(table);  
             editor.horizontalAlignment = SWT.LEFT;  
             editor.grabHorizontal = true;  
             table.setHeaderVisible(true);  
             table.setLinesVisible(true);  
             TableColumn col1 = new TableColumn(table, SWT.LEFT);  
             col1.setText("股票代碼");  
             col1.setWidth(100);  
             TableColumn col2 = new TableColumn(table, SWT.LEFT);  
             col2.setText("公司名");  
             col2.setWidth(100);  
             TableColumn col5 = new TableColumn(table, SWT.LEFT);  
             col5.setText("現價");  
             col5.setWidth(100);  
             TableColumn col3 = new TableColumn(table, SWT.LEFT);  
             col3.setText("漲幅");  
             col3.setWidth(100);  
             TableColumn col4 = new TableColumn(table, SWT.LEFT);  
             col4.setText("換手率");  
             col4.setWidth(100);  
             /** 
             * 添加表格數據 
             */ 
           
            
             Stock[] sk = StockServer.getStock();
             final TableItem[] itemArr = new TableItem[sk.length];
             for(int i=0;i<itemArr.length;i++){
             itemArr[i] = new TableItem(table, SWT.LEFT);
             }
             
           final int time=1000;  
              Runnable showTime = new Runnable(){          
                    public void run(){  
                     Stock[] sk = StockServer.getStock();
                     for(int i=0;i<itemArr.length;i++){
                      itemArr[i].setText(new String[] { String.valueOf(sk[i].getId()), String.valueOf(sk[i].getName()), String.valueOf(sk[i].getPrice())
                         });
                     }   
                        display.timerExec(time, this);  
                    }  
              };                  
           display.timerExec(time,showTime);//你的swt程序的display
            
            
             // 刪除菜單  
             Menu menu1 = new Menu(shell, SWT.POP_UP);  
             table.setMenu(menu1);  
             MenuItem menuitem1 = new MenuItem(menu1, SWT.PUSH);  
             menuitem1.setText("刪除");  
             menuitem1.addListener(SWT.Selection, new Listener() {  
              @Override 
              public void handleEvent(Event event) {  
               MessageBox mbox = new MessageBox(shell, SWT.DIALOG_TRIM|SWT.ICON_INFORMATION);  
               mbox.setText("刪除成功");  
               mbox.setMessage("刪除了" + table.getSelectionCount() + "條記錄");  
               table.remove(table.getSelectionIndices());  
               mbox.open();  
              }  
             });  
             // 修改table  
             {}  
          }  
          }



          //運行結果如下:
          不同時段 不同結果














          posted on 2010-11-03 20:40 洛神賦 閱讀(440) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 平顶山市| 凤阳县| 贵州省| 镇坪县| 宽城| 山东| 万宁市| 交城县| 漯河市| 博客| 霍邱县| 吉首市| 利川市| 湛江市| 开远市| 寿阳县| 五大连池市| 北安市| 晋中市| 体育| 兴文县| 武胜县| 荆州市| 临安市| 斗六市| 平谷区| 黄梅县| 新河县| 修武县| 克东县| 自治县| 松原市| 宜城市| 乌鲁木齐市| 柳河县| 康乐县| 舒兰市| 嘉荫县| 南召县| 新乡县| 随州市|