Not signed in (Sign In)

Vanilla 1.1.2 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthoradmin
    • CommentTimeOct 6th 2007
     
    This forum is for discussion of issues directly relating to project 3
    • CommentAuthornddissi
    • CommentTimeOct 11th 2007 edited
     
    the project does not need to look exactly like professor garrett's. intead, you can have the input at the top (north), the 12 buttons in the center, and the 2 buttons at the bottom (south) for clear and send. the 12 buttons in the center can be arranged as border layout also. examples are in the book or on the cd. good luck, will be starting on this asap

    -Nader Dissi
  1.  
    I got the form all made with all the buttons, but has anyone figured out yet how to call to the listener from a different class?? I just don't know the syntax.
    • CommentAuthorjmscott2
    • CommentTimeOct 21st 2007
     
    I started off with one big class that contained all of my variables and objects, then put smaller classes inside the big class. That way all of my listeners and methods could access all of the variables and objects. My program works but I am going to try to separate the classes instead of having just one big one. I think we might have to pass (by reference) some objects such as the text of the display text box between the different classes??
    • CommentAuthoradmin
    • CommentTimeOct 21st 2007
     
    Remember that you can reference objects in other classes within the same project by referencing the classname followed by the object. So this can be done using separate classes. When I created it, I used 3 different classes: The class that had the frame, the class that had the borders, and the class that had the buttons. Listener classes were attached to the border class and the class with the buttons, but sometimes you have to reference objects that are not defined in the class where the listener is, i.e. in the class with the buttons I had a listener for the buttons but it had to append the appropriate digit to the text in a textbox that was an object instatiated in the border class.

    I didn't put any restrictions on how this project could be accomplished, so do whatever works for you, as nddissi mentions above.
    • CommentAuthornddissi
    • CommentTimeOct 21st 2007
     
    i am having trouble. when i click a button, my label where the numbers should show up disappears. when i clear it comes back. no numbers show up tho. any reason for this? also, after clearing, it no longer does this when clicking buttons, but still no numbers
  2.  
    I have my program setup in 3 classes (the driver or main program, a border class, and a grid class). I have two listeners, one in each layout class, but for some reason I am having trouble passing the input results from the grid layout back to the border layout class. Just curious if anyone could throw me a bone, cause other than that, my program is looking splendid.
  3.  
    okay, I got some crap figured out, my only problem is my textfield does not update
    • CommentAuthorzhayes
    • CommentTimeOct 25th 2007
     
    I've got my classes created, but I am having trouble with a couple things. First, I don't know how to add the keypad (which is a grid layout for me) to the main panel (border layout). Second, I could not find pop-ups in the book and cannot figure out how to create the pop-up or a listener for the SEND button to initiate a pop-up. Any help on either of these problems would be great. Thanks

    Zack
  4.  
    The dialog boxes (pop-ups) are covered on page 268, they are pretty easy to implement.

    And you just add the grid layout to the border layout like you would add anything else to it, make an object of you grid class and add it.
    • CommentAuthormdcarr
    • CommentTimeOct 25th 2007
     
    p 268 def made it really easy to do the popup..

    as for the rest of the code I just used the book examples, made a basic JFrame setup and had the call in my first class file which called the second.. and everything else is in my second.. The layout setup (I used grid), my action listener, and the popups. (layout managers starts on page 341)

    I have a seperate actionlistener for each button and code to add the numbers to the text box and run the pop up is within the listeners.

    Don't know if there's a better way, but this is working fine for me, and I'm happy with that since I missed the last 8 weeks of class..

    Michael
    • CommentAuthorjmscott2
    • CommentTimeOct 25th 2007
     
    I just have 2 action listeners. I have one listener for all the keypad buttons. Inside the listener it determines which button was clicked and then adds that character to the text field. I have one listener for the send and clear buttons, it also determines which one was clicked and either displays the dialog box or clears the text field.
    • CommentAuthorjmscott2
    • CommentTimeOct 25th 2007
     
    Is there a way to access the textfield in another class without making the textfield static?

    Inside of my listener I tried:
    PhonePanel.display.setText()
    ... but it said a non-static variable could not be accessed from a static context. Is there a different syntax that we are supposed to use?
  5.  
    I've got my classes separated into three as I think most of you do. My number buttons are arranged into a grid layout and added to my border layout class. However, I am still having problems with getting my text field to update when I use the number pad from a separate class. Any specific help anyone is willing to give would be awesome.
  6.  
    yeah,I have the same problem, and thats my only problem, and its really pissing me off .
    • CommentAuthoradmin
    • CommentTimeOct 25th 2007
     
    Your textbox needs to be declared as static, declared at the very beginning of the class (before the constructor). That way you can reference it by classname.objectname. Here is an excerpt from a web page that describes static variables (aka "class variables"):

    Class Variables
    When a number of objects are created from the same class blueprint, they each have their own distinct copies of instance variables. In the case of the Bicycle class, the instance variables are cadence, gear, and speed. Each Bicycle object has its own values for these variables, stored in different memory locations.
    Sometimes, you want to have variables that are common to all objects. This is accomplished with the static modifier. Fields that have the static modifier in their declaration are called static fields or class variables. They are associated with the class, rather than with any object. Every instance of the class shares a class variable, which is in one fixed location in memory. Any object can change the value of a class variable, but class variables can also be manipulated without creating an instance of the class.

    For example, suppose you want to create a number of Bicycle objects and assign each a serial number, beginning with 1 for the first object. This ID number is unique to each object and is therefore an instance variable. At the same time, you need a field to keep track of how many Bicycle objects have been created so that you know what ID to assign to the next one. Such a field is not related to any individual object, but to the class as a whole. For this you need a class variable, numberOfBicycles, as follows:

    public class Bicycle{

    private int cadence;
    private int gear;
    private int speed;

    // add an instance variable for the object ID
    private int id;

    // add a class variable for the number of Bicycle objects instantiated
    private static int numberOfBicycles = 0;
    ......
    }

    Class variables are referenced by the class name itself, as in
    Bicycle.numberOfBicycles

    This makes it clear that they are class variables.

    FYI, the link to this is:

    http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
  7.  
    Instead of using a static text field, I took the advice from chris and went ahead and passed the text field through the constructor of my grid layout. This ended up working quite well and eliminates some problems with the static text field.
    •  
      CommentAuthorrrhunt
    • CommentTimeOct 26th 2007
     
    I still can not get the text field to display. I also have three classes with two button listeners. I have my Frame, My Grid class (which has my digits and button listener for digits), and my panel class that contains my border layout. How do you pass results from the button listener in the grid class to the text field in the panel class.
    • CommentAuthoradmin
    • CommentTimeOct 26th 2007
     
    The concept of the passed parameter is a great alternative to the static (class) variable, i.e. passing an argument by reference to a constructor gives the constructor the address of the object (the text box), which it, in turn, assigns an instance variable to. Since the instance variable now points to the address of the textbox that was passed in, the constructed object can freely access that memory location and can also write to it. The difference is that the original textbox doesn't need to be declared as a static. Using either approach will work: Use whichever one is easier for you.

    Maybe Mike can elaborate on how he did it with the reference variable passed to the constructor for those that might want to try that method (it might require some redesign, though).
    • CommentAuthornddissi
    • CommentTimeOct 26th 2007
     
    please elaborate Michael
    • CommentAuthortdgray
    • CommentTimeOct 27th 2007
     
    Is there a way to retrieve the name of the button as a string (as in btnOne = new JButton ("1") where "1" is the name) and have one line of code within the listener instead of 12 lines?

    I was thinking:

    event.getSource().getName
    (returns a compile error)

    or

    JButton source = event.getSource()
    source.getName
    (cant convert object to JButton)

    or something along those lines. It would be along cleaner than how I did it.
    • CommentAuthorcdstreit
    • CommentTimeOct 27th 2007
     
    Something I found that I do not recall seeing in the book is how to turn a text field into a output only area. I found this usefull because I did not want the user to be able to type into the text box, and instead only click on the buttons to set the phone number. Since I use textfield.getText in my program to get the number, allowing the user to type in the textfield allows them to add non-numbers to the phone number when the send button was pressed. If this project was really dialing a phone number then allowing a user to put say an "A" into the number could cause an error.

    So to turn the textfield into an output only area of the gui all you need to do is (with a JTextField named textfield)
    textfield.setEditable(false);

    one downside to this is it changes the background color of the textfield to grey, but you can change it back to white with the setBackground method.
    • CommentAuthorkdtaylor
    • CommentTimeOct 27th 2007
     
    This is what i did:
    made the textfield static
    created a static method in the border class that accepts a string variable this method then uses the string and adds it to the previous entry in the textbox and displays it
    called the static method from the if statements in the listenere of the grid class
    i found this method to work well
    • CommentAuthorkdtaylor
    • CommentTimeOct 27th 2007
     
    are we supposed to limit the program so that the user cannont type into the text box? they have to use the buttons only.
    • CommentAuthordantran
    • CommentTimeOct 27th 2007
     
    As long as the program does what it is suppose to do that is the bare minimum which is on the project 3 worksheet. Everything else is for your own benefit, I believe.

    Danny
    • CommentAuthorcdstreit
    • CommentTimeOct 27th 2007
     
    kdtaylor, no i don't think you have to limit the program like I did.

    I just wanted to share that you could make the textbox output only. The real reason i even tried to do it was because in VB i never could get a text box to only be output without the program graying out the textbox, which didn't look right. So I'm sorry if I confused you, but i just wanted to share that it could be done.
    • CommentAuthordafrodin
    • CommentTimeOct 28th 2007
     
    Depending on how you design your program it could be useful to leave the Text Field editable. I implemented my listeners one at a time starting with the Send/Clear buttons, so when I was testing them the only way to see if they worked was to type in the Text Field.
    • CommentAuthorkdtaylor
    • CommentTimeOct 28th 2007
     
    what advantages would there be to create a textbox and set editable to false? wouldnt it have been the same as creating a label? is there any situation where a textbox.setEditable(false) would be better to use than a label?
    •  
      CommentAuthorkamallari
    • CommentTimeOct 28th 2007
     
    I have a question, in my layout, i have a small bar underneath my gridbox and above my clear button that is the color of the background, and i tried editing the dimensions of the gridbox and it isn't being removed. Just wanted to see if anyone had a problem with this and a solution for it.
    • CommentAuthordantran
    • CommentTimeOct 28th 2007
     
    If I put all of my code in one class, will points be taken off for doing this?

    Danny
    • CommentAuthorjmscott2
    • CommentTimeOct 28th 2007
     
    I haven't had that layout problem, and this is how i set up my panels: For my grid panel I set up a 3 by 4 grid layout and then I added the buttons to the panel. For the border layout sections i put the text box in the North, the grid panel in the Center, send button in the East, and clear button in the South. When my program runs there is no background showing, only the textbox and all the buttons.
    • CommentAuthordafrodin
    • CommentTimeOct 28th 2007
     
    Danny

    We can create as many/few classes as we like as well as name them however we want. We weren't given any limits for Project 3.
    • CommentAuthoradmin
    • CommentTimeOct 28th 2007
     
    When I place restrictions on how something needs to be done, it is stated in the assignment. If I don't say something needs to be done a specific way, you have complete flexibility to do it however you would like. The bottom line is that the program has to meet the written specifications (including the General Specifications). Beyond that, it's totally up to you.

    I never specified in this assignment how it needed to be done, so use whatever approach makes sense to you. As is obvious from these postings, you have chosen a variety of approaches, and that's fine. Keep in mind, though, that design should come before coding, so whatever approach you decided to use needs to be justified and documented in your documentation bundle.
    • CommentAuthortdgray
    • CommentTimeOct 28th 2007
     
    "When my program runs there is no background showing, only the textbox and all the buttons."

    Are you still having this problem?

    Is it just the send and clear buttons that aren't showing up? Did you instantiate all the components?
    • CommentAuthortdgray
    • CommentTimeOct 28th 2007
     
    I read your post again, I think I misunderstood what you meant, sorry.
  8.  
    when the send button is clicked should the textfield be cleared or should the user have to press the clear button to enter a new number
    • CommentAuthortdgray
    • CommentTimeOct 28th 2007
     
    It doesn't say specifically in the Project 3 Specifications, so like professor Garrett said anything beyond those specifications is up to you.
  9.  
    kamallari....i was having the same problem with having the small bar, to fix it just dont set a background color for your panel
    •  
      CommentAuthorjsegal
    • CommentTimeOct 28th 2007
     
    i know it is probably really late in the game to be asking questions about the project (hooray procrastination!!)

    but im getting a
    ----jGRASP exec: java Numberframe

    Exception in thread "main" java.lang.NullPointerException
    at Numberpad.<init>(Numberpad.java:45)
    at Numberframe.main(Numberframe.java:19)

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

    when i run. when i compile everything is just peachy.

    I was reading around on some forums with experts and they dont really help. Anyone know of any last minute ideas?

    -Jim
    •  
      CommentAuthorjsegal
    • CommentTimeOct 28th 2007
     
    One of those are pointing to my

    clear.addActionListener (listener);

    after the send.addActionListener

    and the other is pointing to

    Numberpad panel = new Numberpad();

    which is my borderpanel.
    •  
      CommentAuthorrrhunt
    • CommentTimeOct 29th 2007
     
    Make sure you set your preferred size. It happened to me as well. Set your preferred size in your panel.
    •  
      CommentAuthorjsegal
    • CommentTimeOct 29th 2007
     
    well how do i go about doing that?
    •  
      CommentAuthorrrhunt
    • CommentTimeOct 29th 2007
     
    setPreferredSize (new Dimension (250,180));
    •  
      CommentAuthorjsegal
    • CommentTimeOct 29th 2007
     
    nopers. that didnt work.
    •  
      CommentAuthorrrhunt
    • CommentTimeOct 29th 2007
     
    Make sure you have the button declarations written correctly.
    • CommentAuthordantran
    • CommentTimeOct 29th 2007
     
    Just to make sure I am doing this correctly. Rather than submitting the source code to the website, we are attaching the code in an email to Professor Garrett?

    Danny
  10.  
    We are supposed to attach the java files to an email in WebCT for this project.
    •  
      CommentAuthorkamallari
    • CommentTimeOct 29th 2007
     
    oh yeah i figured out my problem awcappellano, just don't define the size for the gridbox and it disappears, thanks anyways though.
    • CommentAuthornddissi
    • CommentTimeOct 30th 2007
     
    i know this is late but, i wanted to let everyone know how i did it. i just declared the buttons in my numpad as static and my if statement called for each button seperately, like "numpad.num1" without the prefix, it didnt know what button i was talking about.