News:

MFG's Character of the Month: October 2026 Nominations

Main Menu

Stupid Java Program

Started by Mgbenz, December 18, 2008, 09:33:14 PM

Previous topic - Next topic

Mgbenz

Gawd, this makes my brain hurt. I don't why our teacher wanted us to make this. We haven't even discussed event handling yet.... --;

So anyone want to work on this? It's a rather simple Ticketing Service Program though it has a fake login screen. It would probably take just a few minutes for someone who already knows java.

http://moogen.piiym.net/files/temp/JavaApplication1.zip

It's a Netbeans Project btw.

Valodim

..I don't understand the question.

Mgbenz

Well I'm just asking someone to continue the program. I've already made the gui for both windows and the codes for the login window, even though the events don't work for some reason. I really have no clue about event handling. I was just using logic to try to understand it but I still end up nowhere.

Valodim

..so what is it even supposed to do? three words are hardly a complete description :P

Mgbenz

Oh sorry...uhm...I completely suck at explaining things but here goes...

Well, the login window which always has the same username and pass ("admin" and "password" respectively) will show the Ticketing Service Window. The Ticketing Service window works like this.

- user enters his accomodation and it will show up in the Cost: box
- user enters his status, it will calculate the discount according to his status and will show up in the Discount: box
- the cost will be discounted and the total cost will show up in the Total Cost box
- user enters his desired payment
- user's change will be shown in the Change: box

.....I hope that makes sense. >_<

aokmaniac13

Ok here's what you need to do:

Java components have certain events that they trigger when you do stuff to them, for example, a text box might trigger a valueChanged() event or whatnot.
So, tell your main class to extend a Listener class, and for each component you need to keep track of, add your main class (this) as the listener.
Then, override the appropriate methods to cover events that get triggered.  Here's an example of how to handle JButtons, you can look at the Java API to see how other JComponents work.  Different components need different listeners, and I usually need to look it up when I use them :P

public class buttonDemo extends ActionListener
{
   ...
   JButton button = new JButton("Click Me!");
   button.setActionCommand("clicked");
   button.addActionListener(this);
   ...
   public void ActionPerformed(ActionEvent e)
   {
      if(e.getActionCommand().equals("clicked"))
      {
         System.out.println("You clicked the button!");
      }
   }
   ...
}


So event handling is pretty simple as long as you have the following:
- A component that triggers events
- A listener which handles the events that is attached to the component