Results 1 to 3 of 3
Thread: Challenging error
- 11-15-2009, 09:38 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
Challenging error
Java Code:import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JButton; import javax.swing.Icon; import javax.swing.ImageIcon; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class class2 extends JFrame{ JButton movie1; JButton movie2; JButton movie3; JButton movie4; JButton result; public String nom; static int chk=0; public class2(){ super("Movie Name Guess Game..."); setLayout(new FlowLayout()); Icon a = new ImageIcon(getClass().getResource("a.png")); Icon b = new ImageIcon(getClass().getResource("b.png")); Icon c = new ImageIcon(getClass().getResource("c.png")); Icon d = new ImageIcon(getClass().getResource("d.png")); Icon e = new ImageIcon(getClass().getResource("e.png")); Icon f = new ImageIcon(getClass().getResource("f.png")); Icon g = new ImageIcon(getClass().getResource("g.png")); Icon h = new ImageIcon(getClass().getResource("h.png")); movie1 = new JButton(a); movie2 = new JButton(b); movie3 = new JButton(c); movie4 = new JButton(d); result = new JButton("RESULT"); movie1.setRolloverIcon(e); movie2.setRolloverIcon(f); movie3.setRolloverIcon(g); movie4.setRolloverIcon(h); add(movie1); add(movie2); add(movie3); add(movie4); add(result); thehandler handler = new thehandler(); movie1.addActionListener(handler); movie2.addActionListener(handler); movie3.addActionListener(handler); movie4.addActionListener(handler); result.addActionListener(handler); } public class thehandler implements ActionListener{ public void actionPerformed(ActionEvent event){ [COLOR="Teal"]if(event.getSource()==movie1){ nom = JOptionPane.showInputDialog("Guess the name of this awesome movie about a struggle of a man."); if(nom == "Pursuit of Happyness" || nom == "pursuit of happyness" || nom == "PURSUIT OF HAPPYNESS") increasechk(); }[/COLOR] else if(event.getSource()==movie2){ nom = JOptionPane.showInputDialog("Guess the name of this amazing story of a thief."); if(nom == "Oye Lucky Lucky Oye" || nom== "oye lucky luck oye" || nom == "OYE LUCKY LUCKY OYE" || nom =="OLLO" || nom == "ollo") increasechk(); } [COLOR="Red"]else if(event.getSource()==movie3){ nom = JOptionPane.showInputDialog("Guess the name of this all time superhit Shahrukh Khan."); if(nom == "DDLJ" || nom == "ddlj" || nom == "Dilwale Dulhania Le Jayenge") increasechk(); }[/COLOR] [COLOR="Magenta"]else if(event.getSource()==movie4){ nom = JOptionPane.showInputDialog("Guess the name of this all time favourite comedy movie."); if(nom == "Andaz Apna Apna" || nom == "ANDAZ APNA APNA" || nom == "Andaaz Apna Apna" || nom == "andaaz apna apna" || nom == "andaz apna apna" ) increasechk(); }[/COLOR] [COLOR="DimGray"]else if(event.getSource()==result) checkresult();[/COLOR] } } public static void increasechk(){ chk++; } public static void checkresult(){ if(chk == 4) JOptionPane.showMessageDialog(null,"U Rock man. All Correct. U hava a good taste of movies."); if(chk == 3) JOptionPane.showMessageDialog(null,"Good man. 3 correct answers. Good Going."); if(chk == 2) JOptionPane.showMessageDialog(null,"Average Performance. U will die as an average person."); if(chk == 1) JOptionPane.showMessageDialog(null,"Only one correct. Thats bad. Watch all of these man."); if(chk == 0) JOptionPane.showMessageDialog(null,"Thats really poor. U dont deserve to live. Start watching some good movies."); } }
- 11-15-2009, 09:39 PM #2
Member
- Join Date
- Nov 2009
- Posts
- 7
- Rep Power
- 0
main class
[mod: code tags added]Java Code:import javax.swing.JFrame; public class mainclass { public static void main(String[] args){ class2 obj = new class2(); obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); obj.setVisible(true); obj.setSize(550,510); } }
Guys this is my main class. Actually the problem i m facing is the value of chk variable never changes even i enter name of all movies right.
even the increasechk() function is never called. i came to know after debugging.
please help...
what i feel is that in the coloured part of codes in actionPerformed function there is error in compairing nom == "Pursuit of Happyness" nd similarly in other else if conditions..... plss help guys. thanx in advance.. :confused:
-
Similar Threads
-
challenging error
By diwakardelhi in forum AWT / SwingReplies: 3Last Post: 11-15-2009, 09:43 PM -
non preemptive scheduling.....challenging!!
By snehil2009 in forum New To JavaReplies: 5Last Post: 11-10-2009, 09:23 AM -
java.lang.Error: Error opening DSound for capture
By NARs in forum NetworkingReplies: 1Last Post: 10-26-2009, 04:38 PM -
challenging problems
By jayant3001 in forum JCreatorReplies: 24Last Post: 10-30-2008, 05:41 AM -
Is it possible to make this in Java? Challenging question.
By matt_well in forum New To JavaReplies: 24Last Post: 07-29-2008, 04:04 PM


LinkBack URL
About LinkBacks

Bookmarks