?? brokergui.java
字號:
String tempShare = strShares[i].trim();
symbol=tempShare.substring(0,tempShare.indexOf(" "));
price=tempShare.substring(tempShare.indexOf(" "),tempShare.lastIndexOf(" "));
quantity=tempShare.substring(tempShare.lastIndexOf(" "));
System.out.println("gui get shares end ");
Stock st=new Stock(symbol, Float.parseFloat(price.trim()));
System.out.println("gui get shares end2 ");
Share sh=new Share(st,Integer.parseInt(quantity.trim()));
System.out.println("gui get shares end3 ");
shares.add(sh);
System.out.println("gui get shares :shares'length ="+shares.size());
}
System.out.println("gui get shares end ");
}
}catch(Exception e){
System.err.println(e.getMessage());
}
//Share sh=(Share)shares.get(0);
//System.out.println( "shares="+sh.getQuantity());
return shares;
}
//end
//modified by ourteam 051228
//begin
public String getStockSymbolOnCustPan(){
return symbolTf.getText();
}
public String getStockPriceOnCustPan(){
return priceTf.getText();
}
//endt
public Customer getCustomerOnCustPan(){
return new Customer
(idTf.getText(), nameTf.getText(), addrTf.getText());
}
public void showCard(String cardStr){
System.out.println("showCard(" + cardStr +")");
card.show(cardPan, cardStr);
}
public BrokerGui() {
System.out.println("BrokerGui");
buildDisplay();
}
//private and protected methods
private void buildDisplay(){
frame = new JFrame("BrokerTool");
buildSelectionPanel(); // build selection panel
buildCustPanel(); // build customer panel
//modified by ourteam 051228
//begin
buildPortPanel();
//end
buildAllCustPanel(); // build allCustomer panel
//modified by ourteam 051228
//begiin
buildStockPanel();
//buildAllStockPanel();
//end
buildLogPanel(); // build log panel
// add panels to cardPan
cardPan.setLayout(card);
cardPan.add(custPan, "customer");
//modified by ourteam 051228
//begin
cardPan.add(portPan,"portfolio");
//end
cardPan.add(allCustPan, "allcustomers");
//modified by ourteam 051228
//begin
cardPan.add(stockPan, "stock");
//cardPan.add(allStockPan, "allstocks");
//end
// build and display frame
contentPane = frame.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(cardPan, BorderLayout.CENTER);
contentPane.add(selPan, BorderLayout.NORTH);
contentPane.add(logPan, BorderLayout.SOUTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible( true );
// showCard("allcustomers");
}
//build selection panel
private void buildSelectionPanel() {
selPan.setLayout(new GridLayout(1,4));
selPan.add(custBt);
selPan.add(portBt);
selPan.add(allCustBt);
selPan.add(stockBt);
}
public void addSelectionPanelListeners(ActionListener a[]) {
int len = a.length;
if (len !=4) {
System.out.println("BrokerGui addCustPanListeners error "
+ "incorrect array len " + len);
return;
}
custBt.addActionListener(a[0]);
allCustBt.addActionListener(a[1]);
portBt.addActionListener(a[2]);
stockBt.addActionListener(a[3]);
}
//build customer panel
private void buildCustPanel() {
custPan.setLayout(new GridLayout(5,2));
custPan.add(nameLb);
custPan.add(nameTf);
custPan.add(idLb);
custPan.add(idTf);
custPan.add(addrLb);
custPan.add(addrTf);
custPan.add(getBt);
custPan.add(updBt);
custPan.add(addBt);
custPan.add(delBt);
}
public void addCustPanelListeners(ActionListener a[]) {
int len = a.length;
if (len !=4) {
System.out.println("BrokerGui addCustPanListeners error "
+ "incorrect array len " + len);
return;
}
getBt.addActionListener(a[0]);
addBt.addActionListener(a[1]);
delBt.addActionListener(a[2]);
updBt.addActionListener(a[3]);
}
//modified by ourteam 051228
//begin
private void buildPortPanel() {
portPan.setLayout(new GridLayout(5,2));
portPan.add(nameLp);
portPan.add(nameTp);
portPan.add(idLp);
portPan.add(idTp);
portPan.add(sharesLp);
portPan.add(sharesSp);
portPan.add(welBp);
portPan.add(getBp);
portPan.add(addBp);
portPan.add(delBp);
}
public void addPortPanelListeners(ActionListener a[]) {
int len = a.length;
if (len !=3) {
System.out.println("BrokerGui addPortPanListeners error "
+ "incorrect array len " + len);
return;
}
getBp.addActionListener(a[0]);
addBp.addActionListener(a[1]);
delBp.addActionListener(a[2]);
//updBt.addActionListener(a[3]);
}
//end
//build all customer panel
private void buildAllCustPanel() {
allCustPan.setLayout(new BorderLayout());
allCustPan.add(allCustLb, BorderLayout.NORTH);
//** 1 For the JTable exercise comment following 2 lines
//allCustPan.add(allCustSp, BorderLayout.CENTER);
tableModel1 = new DefaultTableModel(tableHeaders1, 20);
table1 = new JTable(tableModel1);
tablePane11 = new JScrollPane(table1);
allCustPan.add(tablePane11, BorderLayout.CENTER);
//allCustTa.setText("all customer display TBD in mod 9");
//** 2 Create a DefaultTableModel and assign it to
//** tableModel. Hint - see TableExample class
//** 3 Create a JTable and assign it to
//** table. Hint - see TableExample class
//** 4 Create a JScrollPane object to scroll the table
//** and assign it to tablePane;
//** 5 Add the tablePan to CENTER region of allCustPan
//** Hint - this line is similar but not the same as
//** the commented out code under step 1.
//Optional lines - uncomment to set size of viewport
Dimension dim1 = new Dimension(500, 150);
table1.setPreferredScrollableViewportSize(dim1);
// table.setPreferredScrollableViewportSize(dim);
}
//modified by ourteam 051228
//begin
//build customer panel
private void buildStockPanel() {
stockPan.setLayout(new GridLayout(4,2));
stockPan.add(symbolLb);
stockPan.add(symbolTf);
stockPan.add(priceLb);
stockPan.add(priceTf);
stockPan.add(getBf);
stockPan.add(addBf);
stockPan.add(allStockLb);
//allCustPan.setLayout(new BorderLayout());
//stockPan.add(allStockLb, BorderLayout.NORTH);
//** 1 For the JTable exercise comment following 2 lines
//stockPan.add(allStockSp, BorderLayout.CENTER);
//allCustTa.setText("all customer display TBD in mod 9");
//stockPan.add(allStockSp);
tableModel2 = new DefaultTableModel(tableHeaders2, 20);
table2 = new JTable(tableModel2);
tablePane12 = new JScrollPane(table2);
stockPan.add(tablePane12);
Dimension dim2 = new Dimension(50, 10);
table2.setPreferredScrollableViewportSize(dim2);
//allStockTa.setText("all stock display TBD in mod 9");
}
public void addStockPanelListeners(ActionListener a[]) {
int len = a.length;
if (len !=2 ) {
System.out.println("BrokerGui addStockPanListeners error "
+ "incorrect array len " + len);
return;
}
getBf.addActionListener(a[0]);
allStockLb.addActionListener(a[1]);
}
//build all customer panel
/*private void buildAllStockPanel() {
allStockPan.setLayout(new BorderLayout());
allStockPan.add(allStockLb, BorderLayout.NORTH);
//** 1 For the JTable exercise comment following 2 lines
allStockPan.add(allStockSp, BorderLayout.CENTER);
allStockTa.setText("all stock display TBD in mod 9");
Dimension dim = new Dimension(500, 150);
// table.setPreferredScrollableViewportSize(dim);
}*/
//end
//build message log panel
private void buildLogPanel() {
logPan.setLayout(new BorderLayout());
logPan.add(logLb, BorderLayout.NORTH);
logPan.add(logSp, BorderLayout.CENTER);
}
public static void main(String args[]){
BrokerGui gui = new BrokerGui();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -