I am new at making gui's so this is my first, The assignment was to make a gui for a blackjack game and I am having event handling problems. "myhand" is a list box field in the gui, and "hit" is a button that just draws a card and then adds it to the hand() which is a vector and puts it in the list box. Can anyone help??? _______________________________________________________ Here are the errors.
--------------------Configuration: JDK version 1.3 <Default>------------------------------------------------ C:\PROGRA~1\XIN OXS~1\JCreator\MYPROJ~1\BLACKJ~1\BJcontrols.java:106: cannot resolve symbol symbol : variable hit location: class BJcontrols.gameActionListener if(source==hit) ^ C:\PROGRA~1\XINOXS~1\JCreator\MYPROJ~1\BLACKJ~1\BJcontrols.java:111: cannot resolve symbol symbol : variable myhand location: class BJcontrols.gameActionListener myhand.append(c1+"\n",0); ^ 2 errors Process completed. _______________________________________________________ Here is the Jframe code. import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class BJcontrols extends JFrame { /*This is the class where I declare and instantiate my buttons any other interface Components.*/
public BJcontrols() { super("BLACKJACK"); setSize(500,400); setLocation(200,200);
//sets up the score label. JLabel score=new JLabel("Score",SwingConstants.CENTER); score.setFont (new Font ("Times New Roman", Font.BOLD, 25));
//sets up playing field labels JLabel mhandlabel=new JLabel("My Hand",SwingConstants.LEFT); mhandlabel.setFont (new Font ("Times New Roman", Font.BOLD, 12)); JLabel comphandlabel=new JLabel("Computers Hand",SwingConstants.RIGHT); comphandlabel.setFont (new Font ("Times New Roman", Font.BOLD, 12));
//My Buttons& fields JButton hit=new JButton("Hit"); JButton stay=new JButton("Stay"); JButton deal=new JButton("DEAL"); JButton exit=new JButton("EXIT"); List myhand=new List(13); List computerhand=new List(13); List score_box=new List(1);
//Creates a new container. Container contentPane = getContentPane(); contentPane.setLayout(null);
//Adds buttons, fields, labels to the container. contentPane.add(hit); contentPane.add(stay); contentPane.add(deal); contentPane.add(exit);
//These are the text fields. myhand.setBounds(10 + insets.left,90+ insets.top,175,200); computerhand.setBounds(305 + insets.left,90+ insets.top,175,200);
You have declared both, the JButtton "hit" and the List "myhand" inside the constructor BJcontrols(). You have to declare these globally because you are accessing these components outside the constructor. Try with declaring these components globally and let me know the result.
when I declare the jbutton hit, and the text field myhand out side the field I get a deprication error.
here it is: --------------------Configuration: JDK version 1.3 <Default>------------------------------------------------ Note: C:\PROGRA~1\XINOXS~1\JCreator\MYPROJ~1\BLACKJ~1\BJcontrols.java uses or overrides a deprecated API. Note: Recompile with -deprecation for details. Process completed.
hey, I tried making List---->JList and it didn't like it. I don't think there is a JList. Right now I press the hit button and the first card in the deck appears "AceOfClubs" and I will keep pressing hit and it will keep adding AceOfClubs to the list as many times as I press hit. Do you think this has to do with the deprication. Thanks, jake.
hey nevermind the last post, I figuared out why I was always getting "AceOfClubs". It was because everytime an action happened I was making a new deck and hand. But it works fine, there is still a deprication error though. Do you think it matters??? jake.
Actually the components which start with the letter "J" are all Swing components and the rest are AWT components. When you are trying to develop the GUI in Swings then use only Swing Components. That's why you will have JList in Swing instead of List.
yeah I finaly found out what I was doing wrong, the JList constructor just needed a parameter. Now I just have to find out how to add a card to the JList. Thank you for all your help though. jake.