Home / Swinger Videos / Advanced Java: Swing (GUI) Programming Part 5 — Event Handling
Advanced Java: Swing (GUI) Programming Part 5 — Event Handling

Advanced Java: Swing (GUI) Programming Part 5 — Event Handling

Complete course: http://www.udemy.com/java-swing-complete/?couponCode=youtube A tutorial on how to implement custom events and how to deal with events genera…

Introduction to Object Oriented Programming: Java Swing Events (part 6/8)

25 comments

  1. gotcha

  2. caveofprogramming

    I cover various options along these lines in the full course. Yes, you can download the course if you subscribe too. Best way is to use a CardLayout to switch views. You could alternatively just create a new window and set the old one to invisible, but best practice is to stick with one window and just change the view in it.

  3. MikesonStudentSD

    Hi how would you go about using a button to open up a new jpanel and disposing of the old one with the set up you have here. Ie first diplay has a button that goes to second display and first display is disposed of. Do you cover this in you paid swing tutorials also can you down load them. To reduce data cost if watchin same vid over and over.

  4. MikesonStudentSD

    Perfect Swing Series exactly what I’ve been looking for. Clear and precise this series will help me alot. Thx’s

  5. caveofprogramming

    Hi Richard, I’m not sure if that’s a good description of it or not. The stuff I go through here is known as the “observer pattern” — it you look at my channel, you can find three videos on it that break it down a lot more than this video. This video also goes over some unnecessary detail really — it was my first stab at explaining this. The thing is that if you call one components’s methods from another, those two components are permanently intertwined, and not very reusable.

  6. Button.addActionListener(new ActionListener(){

    @Override
    public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    TextArea.append(detailspanel.GetString());
    }

    });

  7. Okay, well i did what i said and it works and makes more sense to me to do. Is my way considered bad practice? Does calling a function back like that slow down processing time? I believe my way keeps things a bit neater and file size down a little. is this fine?

  8. Couldn’t you create a separate function containing the function call of the event listener inside the details panel class and call details panel an object in the MainFrame and call its function? I will subscribe, but can you explain absolutely everything without bouncing between class tabs? Great video’s.

  9. Im not the best programmer in the world, as i know basic c++, C.net, most web application programming, but i just don’t understand what your doing essentially with creating your own object listener. Assume, i’m using notepad (cause i am). This is my interpretation after reading your code.. Your Calling the action that occurred inside the details panel so your class can interpret the input into the textfield on the east? If that’s correct-

  10. Simply awesome.

  11. test

  12. Diogo Pacheco Pedro

    Awesome tutorial! thanks

  13. I just want to say thank you so much for this. It really helped me out of the rough patch I’ve been on. One can only go so far with a trial and error method. xD

  14. All I know is that I jumped way ahead of what I know in this video

  15. No i think this video is very learning nothing wrong with it 🙂 thanks for a great tutorial !

  16. caveofprogramming

    getListenerList() just returns objects of type “Object”. But these objects are really various kinds of listeners, depending on what you added to the list. So you have to cast to the correct type so that you can call specific methods of the particular type of listener. Mind you, I keep meaning to remake this video … it would be simpler not to use this listener list thing at all but just to use a reference to the listener.

  17. I didnt get why you cast in the if statement ?

  18. DerFlatulator6

    Universities tend to drill the basics into your head pretty hard… Probably for the best.
    Looking forward to more tutorials. I didn’t notice a problem with your mic though.

  19. caveofprogramming

    Yeah, your Java has to be pretty good to get through this I think! I actually plan to make a simpler version of this as soon as I’ve obtained a better mic. This stuff is probably overkill for most applications — you can set up a simple “callback”-type mechanism that does the job with just one interface and a few lines of code.

  20. I found it fast paced, but I understood it all due to my pretty solid understanding of basic Java. I think it’s good that you went over creating custom event listeners, otherwise I probably would have done it the default way, and I can see now how that could get messy. Probably took me about 30mins to get through the video though 😛

  21. Я ничего не понял.

  22. caveofprogramming

    In this app that would be fine, but as your program grows in complexity, it tends to become unmaintainable. So the idea is to try to route all events through a central place. Having said that, this video tries to fit in much too much to 15 mins and the solution I present is overkill in the context … I intend to remake it very soon, giving a variety of solution.

  23. Why not just add actionlistners to the add button, and in the actionperformed method simply use an if statement, like if the add button is pushed, you append the string with the content in the textarea? Wouldnt that be much simpler? This whole detaillistener confused me :/

  24. Thanks for the tutorials, they’ve really helped me understand java gui a lot better. I learned a bit about events too!

  25. caveofprogramming

    Don’t worry, I had to go really fast in this one to fit it all in. If you get the basic idea, just copy the code (it’s on caveofprogramming . com).

Scroll To Top