ใกล้ถึงเวลาต้องก็อป - นำส่ง - ตอบคำถาม แต่ยังรันจาวาไม่ผ่าน
[img]http://s21.postimg.org/hv8ej9tvr/Untitled.png[/img]
[img]http://s23.postimg.org/htrizh0kr/Untitled.png[/img]
อะไรคือสาเหตุที่ทำให้เพื่อนรันได้ แต่ผมรันไม่ได้หรอครับ (ตอนวันสอบก็พลาดเพราะเออเร่อ 2 บรรทัดนี้)
โปรแกรม Eclipse Juno ครับ
วันจันทร์ถึงเวลาแก้ตัว เอางานไปส่ง (ถ้ารันผ่าน ก็ต้องตอบคำถามแกให้ได้อีกทีว่าทำตรงนี้ตรงนั้นได้เพราะอะไร)
หรือมีใครรันโค้ดข้างล่างนี้ได้บ้างมั้ยครับ
หน้าตาของเดิม
http://s17.postimg.org/esx9rumgv/Project_My_Screen_App_2015_05_17_02_19_01_25.jpg
หน้าตาของโปรแกรมที่อาจารย์อยากเห็น
http://s30.postimg.org/h95dklp69/Project_My_Screen_App_2015_05_17_02_19_06_16.jpg
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
import javax.swing.event.*;
public class CartoonRent extends JFrame {
JPanel p; ButtonGroup bg; JComboBox mcombo;
JList scrollingList,scrollingList1,scrollingList2;
JRadioButton n0,n1,n2,n3;
JLabel datelbl,namelbl,piclbl,cnamelbl,cadslbl,blanklbl;
JButton calcbtn,resetbtn,closebtn;
JTextField nametxt,teltxt; Icon ani;
Font fn = new Font("Tahoma",Font.PLAIN,18);
String msg="", day=""; float d,baht;
public CartoonRent (String title) {
super(title);
String bookList[] = {" ไทย ", " อเมริกา ", " จีน "};
String bookList1[] = {" สารคดี ", " Action ", " Cartoon "};
String bookList2[] = {" Doraemon ", " A-Ra-Re ", " DragonBall ", " BirdLand "," Pung-Pong "," นเรศวร "," วันสิ้นโลก "," เนปาล "};
p = new JPanel();
p.setLayout (new GridBagLayout());
ani = new ImageIcon("TITLE.gif");
piclbl = new JLabel(ani,SwingConstants.LEFT);
cnamelbl = new JLabel("TELEZZA T.L. Group");
cadslbl = new JLabel("Bangkok. 088-818-8216");
Date DateName = new Date();
SimpleDateFormat df = new SimpleDateFormat("d/M/yyyy");
String dd = df.format(DateName.getTime());
datelbl = new JLabel("Date : " + dd + " ");
namelbl = new JLabel("Customer Name");
nametxt = new JTextField(15);
bg = new ButtonGroup();
n0 = new JRadioButton(); bg.add(n0);
n1 = new JRadioButton("5 day"); bg.add(n1);
n2 = new JRadioButton("10 day"); bg.add(n2);
n3 = new JRadioButton("1 month"); bg.add(n3);
blanklbl = new JLabel("");
ani = new ImageIcon("calculate.gif");
calcbtn = new JButton("calculation",ani);
ani = new ImageIcon("reset.gif");
resetbtn = new JButton("reset",ani);
ani = new ImageIcon("close.gif");
closebtn = new JButton("close",ani);
p.setBackground(Color.white);
cnamelbl.setFont(fn);
cadslbl.setFont(fn);
datelbl.setFont(fn);
namelbl.setFont(fn);
nametxt.setFont(fn);
calcbtn.setFont(fn);
resetbtn.setFont(fn);
closebtn.setFont(fn);
n1.setFont(fn);
n2.setFont(fn);
n3.setFont(fn);
scrollingList = new JList(bookList);
scrollingList.setFont(fn);
scrollingList.setPreferredSize(new Dimension(150, 200));
scrollingList.setVisibleRowCount(4);
scrollingList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollingList1 = new JList(bookList1);
scrollingList1.setFont(fn);
scrollingList1.setPreferredSize(new Dimension(150, 200));
scrollingList1.setVisibleRowCount(4);
scrollingList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollingList2 = new JList(bookList2);
scrollingList2.setFont(fn);
scrollingList2.setPreferredSize(new Dimension(150, 200));
scrollingList2.setVisibleRowCount(4);
scrollingList2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
String discount[] = {" discount 3% ", " discount 10% "," discount 50% ", " discount 100% "};
mcombo = new JComboBox(discount);
mcombo.setFont(fn);
mcombo.setPreferredSize(new Dimension(180, 30));
AddPanel x = new AddPanel();
x.addItem(p,piclbl,0,0,1,3,GridBagConstraints.WEST);
x.addItem(p,cnamelbl,1,0,3,1,GridBagConstraints.WEST);
x.addItem(p,cadslbl,1,1,3,1,GridBagConstraints.WEST);
x.addItem(p,datelbl,1,2,3,1,GridBagConstraints.EAST);
x.addItem(p,namelbl,0,4,2,1,GridBagConstraints.WEST);
x.addItem(p,nametxt,2,4,2,1,GridBagConstraints.CENTER);
x.addItem(p,new JScrollPane(scrollingList),0,6,2,2,GridBagConstraints.WEST);
x.addItem(p,new JScrollPane(scrollingList1),2,6,2,2,GridBagConstraints.WEST);
x.addItem(p,new JScrollPane(scrollingList2),4,6,2,2,GridBagConstraints.WEST);
x.addItem(p,n1,0,8,1,1,GridBagConstraints.WEST);
x.addItem(p,n2,1,8,1,1,GridBagConstraints.WEST);
x.addItem(p,n3,2,8,1,1,GridBagConstraints.WEST);
x.addItem(p,mcombo,0,10,2,1,GridBagConstraints.WEST);
x.addItem(p,blanklbl,0,8,4,1,GridBagConstraints.WEST);
x.addItem(p,calcbtn,0,12,2,1,GridBagConstraints.WEST);
x.addItem(p,resetbtn,2,12,1,1,GridBagConstraints.WEST);
x.addItem(p,closebtn,4,12,1,1,GridBagConstraints.WEST);
calcbtn.addActionListener(new ButtonListener());
resetbtn.addActionListener(new ButtonListener());
closebtn.addActionListener(new ButtonListener());
n1.addActionListener(new RadioButtonListener());
n2.addActionListener(new RadioButtonListener());
n3.addActionListener(new RadioButtonListener());
mcombo.addActionListener(new ComboListener());
scrollingList.addListSelectionListener(new ListListener());
scrollingList1.addListSelectionListener(new ListListener());
scrollingList2.addListSelectionListener(new ListListener());
add(p);
}
private class ListListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
msg = (String) scrollingList.getSelectedValue();
msg = (String) scrollingList1.getSelectedValue();
msg = (String) scrollingList2.getSelectedValue();
}
}
private class RadioButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == n1) {
day = "5 วัน";
baht = 50.0f;
}
if (source == n2) {
day = "10 วัน";
baht = 100.0f;
}
if (source == n3) {
day = "1 เดือน";
baht = 300.0f;
}
}
}
private class ComboListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
int idx = mcombo.getSelectedIndex();
switch (idx) {
case 0: d=0.03f;
break;
case 1: d=0.10f;
break;
case 2: d=0.50f;
break;
case 3: d=1.00f;
break;
}
}
}
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 (scrollingList.isSelectionEmpty()) {
JOptionPane.showMessageDialog(null,"เลือกรายการที่ต้องการเช่าด้วยค่ะ !!!");
}
else if (scrollingList1.isSelectionEmpty()) {
JOptionPane.showMessageDialog(null,"เลือกรายการที่ต้องการเช่าด้วยค่ะ !!!");
}
else if (scrollingList2.isSelectionEmpty()) {
JOptionPane.showMessageDialog(null,"เลือกรายการที่ต้องการเช่าด้วยค่ะ !!!");
}
else if (!n1.isSelected() && (!n2.isSelected() && (!n3.isSelected()))) {
JOptionPane.showMessageDialog(null,"เลือกจำนวนวันด้วยค่ะ !!!");
}
else {
String m = "คุณ " + nametxt.getText() +" เช่า" + msg + day
+ " = " + new Float(baht).toString()+ " บาท" ;
JOptionPane.showMessageDialog(null,m);
}
}
if(source==resetbtn) {
nametxt.setText("");
n0.setSelected(true);
scrollingList.clearSelection();
scrollingList1.clearSelection();
scrollingList2.clearSelection();
}
if (source==closebtn) {
dispose();
}
}
}
public static void main(String args[]) {
CartoonRent f = new CartoonRent("CarToon DVD Rental");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(800, 600);
f.setVisible(true);
}
}
ตั้งใจจะเอาโค้ดเพื่อนมาแคะดูเนื้อใน แต่รันไม่ผ่าน เลยไม่รู้จะเริ่มยังไง ช่วยหน่อยครับ (Java)
[img]http://s21.postimg.org/hv8ej9tvr/Untitled.png[/img]
[img]http://s23.postimg.org/htrizh0kr/Untitled.png[/img]
อะไรคือสาเหตุที่ทำให้เพื่อนรันได้ แต่ผมรันไม่ได้หรอครับ (ตอนวันสอบก็พลาดเพราะเออเร่อ 2 บรรทัดนี้)
โปรแกรม Eclipse Juno ครับ
วันจันทร์ถึงเวลาแก้ตัว เอางานไปส่ง (ถ้ารันผ่าน ก็ต้องตอบคำถามแกให้ได้อีกทีว่าทำตรงนี้ตรงนั้นได้เพราะอะไร)
หรือมีใครรันโค้ดข้างล่างนี้ได้บ้างมั้ยครับ
หน้าตาของเดิม
http://s17.postimg.org/esx9rumgv/Project_My_Screen_App_2015_05_17_02_19_01_25.jpg
หน้าตาของโปรแกรมที่อาจารย์อยากเห็น
http://s30.postimg.org/h95dklp69/Project_My_Screen_App_2015_05_17_02_19_06_16.jpg
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.*;
import javax.swing.event.*;
public class CartoonRent extends JFrame {
JPanel p; ButtonGroup bg; JComboBox mcombo;
JList scrollingList,scrollingList1,scrollingList2;
JRadioButton n0,n1,n2,n3;
JLabel datelbl,namelbl,piclbl,cnamelbl,cadslbl,blanklbl;
JButton calcbtn,resetbtn,closebtn;
JTextField nametxt,teltxt; Icon ani;
Font fn = new Font("Tahoma",Font.PLAIN,18);
String msg="", day=""; float d,baht;
public CartoonRent (String title) {
super(title);
String bookList[] = {" ไทย ", " อเมริกา ", " จีน "};
String bookList1[] = {" สารคดี ", " Action ", " Cartoon "};
String bookList2[] = {" Doraemon ", " A-Ra-Re ", " DragonBall ", " BirdLand "," Pung-Pong "," นเรศวร "," วันสิ้นโลก "," เนปาล "};
p = new JPanel();
p.setLayout (new GridBagLayout());
ani = new ImageIcon("TITLE.gif");
piclbl = new JLabel(ani,SwingConstants.LEFT);
cnamelbl = new JLabel("TELEZZA T.L. Group");
cadslbl = new JLabel("Bangkok. 088-818-8216");
Date DateName = new Date();
SimpleDateFormat df = new SimpleDateFormat("d/M/yyyy");
String dd = df.format(DateName.getTime());
datelbl = new JLabel("Date : " + dd + " ");
namelbl = new JLabel("Customer Name");
nametxt = new JTextField(15);
bg = new ButtonGroup();
n0 = new JRadioButton(); bg.add(n0);
n1 = new JRadioButton("5 day"); bg.add(n1);
n2 = new JRadioButton("10 day"); bg.add(n2);
n3 = new JRadioButton("1 month"); bg.add(n3);
blanklbl = new JLabel("");
ani = new ImageIcon("calculate.gif");
calcbtn = new JButton("calculation",ani);
ani = new ImageIcon("reset.gif");
resetbtn = new JButton("reset",ani);
ani = new ImageIcon("close.gif");
closebtn = new JButton("close",ani);
p.setBackground(Color.white);
cnamelbl.setFont(fn);
cadslbl.setFont(fn);
datelbl.setFont(fn);
namelbl.setFont(fn);
nametxt.setFont(fn);
calcbtn.setFont(fn);
resetbtn.setFont(fn);
closebtn.setFont(fn);
n1.setFont(fn);
n2.setFont(fn);
n3.setFont(fn);
scrollingList = new JList(bookList);
scrollingList.setFont(fn);
scrollingList.setPreferredSize(new Dimension(150, 200));
scrollingList.setVisibleRowCount(4);
scrollingList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollingList1 = new JList(bookList1);
scrollingList1.setFont(fn);
scrollingList1.setPreferredSize(new Dimension(150, 200));
scrollingList1.setVisibleRowCount(4);
scrollingList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scrollingList2 = new JList(bookList2);
scrollingList2.setFont(fn);
scrollingList2.setPreferredSize(new Dimension(150, 200));
scrollingList2.setVisibleRowCount(4);
scrollingList2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
String discount[] = {" discount 3% ", " discount 10% "," discount 50% ", " discount 100% "};
mcombo = new JComboBox(discount);
mcombo.setFont(fn);
mcombo.setPreferredSize(new Dimension(180, 30));
AddPanel x = new AddPanel();
x.addItem(p,piclbl,0,0,1,3,GridBagConstraints.WEST);
x.addItem(p,cnamelbl,1,0,3,1,GridBagConstraints.WEST);
x.addItem(p,cadslbl,1,1,3,1,GridBagConstraints.WEST);
x.addItem(p,datelbl,1,2,3,1,GridBagConstraints.EAST);
x.addItem(p,namelbl,0,4,2,1,GridBagConstraints.WEST);
x.addItem(p,nametxt,2,4,2,1,GridBagConstraints.CENTER);
x.addItem(p,new JScrollPane(scrollingList),0,6,2,2,GridBagConstraints.WEST);
x.addItem(p,new JScrollPane(scrollingList1),2,6,2,2,GridBagConstraints.WEST);
x.addItem(p,new JScrollPane(scrollingList2),4,6,2,2,GridBagConstraints.WEST);
x.addItem(p,n1,0,8,1,1,GridBagConstraints.WEST);
x.addItem(p,n2,1,8,1,1,GridBagConstraints.WEST);
x.addItem(p,n3,2,8,1,1,GridBagConstraints.WEST);
x.addItem(p,mcombo,0,10,2,1,GridBagConstraints.WEST);
x.addItem(p,blanklbl,0,8,4,1,GridBagConstraints.WEST);
x.addItem(p,calcbtn,0,12,2,1,GridBagConstraints.WEST);
x.addItem(p,resetbtn,2,12,1,1,GridBagConstraints.WEST);
x.addItem(p,closebtn,4,12,1,1,GridBagConstraints.WEST);
calcbtn.addActionListener(new ButtonListener());
resetbtn.addActionListener(new ButtonListener());
closebtn.addActionListener(new ButtonListener());
n1.addActionListener(new RadioButtonListener());
n2.addActionListener(new RadioButtonListener());
n3.addActionListener(new RadioButtonListener());
mcombo.addActionListener(new ComboListener());
scrollingList.addListSelectionListener(new ListListener());
scrollingList1.addListSelectionListener(new ListListener());
scrollingList2.addListSelectionListener(new ListListener());
add(p);
}
private class ListListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
msg = (String) scrollingList.getSelectedValue();
msg = (String) scrollingList1.getSelectedValue();
msg = (String) scrollingList2.getSelectedValue();
}
}
private class RadioButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == n1) {
day = "5 วัน";
baht = 50.0f;
}
if (source == n2) {
day = "10 วัน";
baht = 100.0f;
}
if (source == n3) {
day = "1 เดือน";
baht = 300.0f;
}
}
}
private class ComboListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
int idx = mcombo.getSelectedIndex();
switch (idx) {
case 0: d=0.03f;
break;
case 1: d=0.10f;
break;
case 2: d=0.50f;
break;
case 3: d=1.00f;
break;
}
}
}
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 (scrollingList.isSelectionEmpty()) {
JOptionPane.showMessageDialog(null,"เลือกรายการที่ต้องการเช่าด้วยค่ะ !!!");
}
else if (scrollingList1.isSelectionEmpty()) {
JOptionPane.showMessageDialog(null,"เลือกรายการที่ต้องการเช่าด้วยค่ะ !!!");
}
else if (scrollingList2.isSelectionEmpty()) {
JOptionPane.showMessageDialog(null,"เลือกรายการที่ต้องการเช่าด้วยค่ะ !!!");
}
else if (!n1.isSelected() && (!n2.isSelected() && (!n3.isSelected()))) {
JOptionPane.showMessageDialog(null,"เลือกจำนวนวันด้วยค่ะ !!!");
}
else {
String m = "คุณ " + nametxt.getText() +" เช่า" + msg + day
+ " = " + new Float(baht).toString()+ " บาท" ;
JOptionPane.showMessageDialog(null,m);
}
}
if(source==resetbtn) {
nametxt.setText("");
n0.setSelected(true);
scrollingList.clearSelection();
scrollingList1.clearSelection();
scrollingList2.clearSelection();
}
if (source==closebtn) {
dispose();
}
}
}
public static void main(String args[]) {
CartoonRent f = new CartoonRent("CarToon DVD Rental");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(800, 600);
f.setVisible(true);
}
}