งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

1 String bookList[] = {" Doraemon ", " A-Ra-Re ", " DragonBall ", " BirdLand ", " Pung-Pong "}; JList scrollingList = new JList(bookList); scrollingList.setVisibleRowCount(4);

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "1 String bookList[] = {" Doraemon ", " A-Ra-Re ", " DragonBall ", " BirdLand ", " Pung-Pong "}; JList scrollingList = new JList(bookList); scrollingList.setVisibleRowCount(4);"— ใบสำเนางานนำเสนอ:

1 1 String bookList[] = {" Doraemon ", " A-Ra-Re ", " DragonBall ", " BirdLand ", " Pung-Pong "}; JList scrollingList = new JList(bookList); scrollingList.setVisibleRowCount(4); scrollingList.setSelectionMode (ListSelectionModel.SINGLE_SELECTION); p.add(new JScrollPane(scrollingList)); scrollingList.addListSelectionListener (new ListListener()); private class ListListener implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { msg = (String) scrollingList.getSelectedValue(); }

2 2 ButtonGroup bg = new ButtonGroup(); JRadioButton n1 = new JRadioButton("1 day"); bg.add(n1); JRadioButton n2 = new JRadioButton("3 day"); bg.add(n2); p.add(n1); p.add(n2); n1.addActionListener(new RadioButtonListener()); n2.addActionListener(new RadioButtonListener()); private class RadioButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == n1) { day = "1 วัน "; baht = 10.0f; } if (source == n2) { day = "3 วัน "; baht = 30.0f; }

3 3 String discount[] = {" discount 2% ", " discount 5% "}; JComboBox mcombo = new JComboBox(discount); p.add(mcombo); mcombo.addActionListener (new ComboListener()); private class ComboListener implements ActionListener { public void actionPerformed(ActionEvent e) { int idx = mcombo.getSelectedIndex(); switch (idx) { case 0: d=0.02f; break; case 1: d=0.05f; break; }

4 4 JButton calcbtn = new JButton("calculation"); JButton resetbtn = new JButton("reset"); Jbutton closebtn = new JButton("close"); p.add(calcbtn); p.add(resetbtn); p.add(closebtn); calcbtn.addActionListener(new ButtonListener()); resetbtn.addActionListener(new ButtonListener()); closebtn.addActionListener(new ButtonListener());

5 5 private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == calcbtn) { baht = baht - (d*baht); if (nametxt.getText().equals("")) { JOptionPane.showMessageDialog(null," ป้อนข้อมูลชื่อ ด้วยค่ะ !!!"); } else if (teltxt.getText().equals("")) { JOptionPane.showMessageDialog(null," ป้อนข้อมูลเบอร์ โทรด้วยค่ะ !!!"); } else if (scrollingList.isSelectionEmpty()) { JOptionPane.showMessageDialog(null, " เลือกรายการที่ต้องการเช่าด้วยค่ะ !!!"); } else if (!n1.isSelected() && (!n2.isSelected())) { JOptionPane.showMessageDialog(null," เลือกจำนวนวัน ด้วยค่ะ !!!"); } else { String m = " คุณ " + nametxt.getText() +" เช่า " + msg + day + " = " + new Float(baht).toString()+ " บาท " ; JOptionPane.showMessageDialog(null,m); } } if(source==resetbtn) { nametxt.setText(""); teltxt.setText(""); /* n1.setSelected(false) ; n2.setSelected(false) ; */ n0.setSelected(true); scrollingList.clearSel ection(); } if (source==closebtn) { dispose(); } } } Event Handling on Button

6 6 ผลการทำงานของโปรแกรม ( กรณีเลือก DragonBall, 1 day, discount 5%)

7 7 ผลการทำงานของโปรแกรม ( กรณีเลือก BirdLand, 3 day, discount 2%)


ดาวน์โหลด ppt 1 String bookList[] = {" Doraemon ", " A-Ra-Re ", " DragonBall ", " BirdLand ", " Pung-Pong "}; JList scrollingList = new JList(bookList); scrollingList.setVisibleRowCount(4);

งานนำเสนอที่คล้ายกัน


Ads by Google