• Post Reply Bookmark Topic Watch Topic
  • New Topic

New to Java, and really stuck

 
Ted Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working with Java for a couple months now. However, I'm pretty stuck. I was working on adding a selector on the screen. Searching for code, I found something that some created better than I ever could. I'm trying to integrate it into my code.

I have a program that is pretty MVC.

I'm in my controller class and I'm calling this code:
http://stackoverflow.com/questions/13948122/drawing-a-bounding-rectangle-to-select-what-area-to-record

I've changed it to a runnable and called a wait after I called this class, but it still continues on to the next line.

I'm thinking I'll have to either create a super controller (one that manages two controllers and have a multiple set of views and models) because I'll have multiple views or I'll have to figure out how to wait for it to finish as a thread. As mentioned above, wait() doesn't work.

This is the code in my controller after I changed it back from a Runnable:


Any suggestions?
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there are several pieces of code over on SO, but they all seem to create a JFrame and then return. However I'm not clear as to what it is you hope to wait for. Do you hope to wait for the creation of the JFrame, or the subsequent closing of that JFrame, or something else?
 
Ted Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct, I'm waiting for the jframe to close. The link is pointing to a java program that will allow someone to select a screen size. I want the topleft and bottomright points that a user selects from a screenshot.
 
Ted Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been working on it and this might help.



I'm getting to the "Here message" before the JFrame closes.

Here is the thread I modified:
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you know, Swing applications don't usually work that way. Creating new GUI components in a separate thread just isn't what you do. Normally what you do is to display a component and then attach suitable listeners to it, which respond to whatever actions you choose. You seem to still be working from the point of view of non-GUI applications where your code decides what happens and when it happens, but in a GUI application your code's job is to respond to events related to the GUI.

So, chances are that you're well on your way down the wrong road. Could I suggest you hold up for a while and have a look at the Oracle Swing tutorial?
 
Ted Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right. I'm not using it as intended. I read the link and I'm not much further. I thought about it and I tried to change the whole idea of what I was trying to do, and I think I'm a bit closer. In my other programming world, I would call the class m_dialog = new Dialog(). Then I would call a do modal. m_dialog.DoModal(); The program would set that code to the highest level. I couldn't do anything with the main program because it was a modal dialog box. Do you have a conversion of that into JAVA? That might help me out.
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't that just be a JDialog in Swing? That's what you would use if you wanted a modal dialog. Have a look through that tutorial I linked to, you should be able to find it in there.
 
Ted Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it is. I think JDialog is a modeless dialog.
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ted, you can make a JDialog modal. Read the tutorial and the documentation.
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That reply sounds a bit terse, doesn't it? Sorry about that. But the thing is, it seems like you learned GUI programming in some other language, and now you're trying to use techniques from that other language to write Swing code. And it just isn't working. You need to get rid of that baggage and accept Swing for what it is. If your code tries to fight against the way Swing works, you just aren't going to get anywhere. So I'm going to suggest that you put your plans on hold for a bit and go through the Swing tutorial to find out how to work with the system instead of against it. I can appreciate that you might find that frustrating, but I don't think it's a waste of time.
 
Ted Jones
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out. Although, I don't understand how hard it had to be.

I added an eventlistiner, eventobject and a viewlistiner.

I added in my main for a change in views:


As you can see, I'm passing through my information by WindowPointEvent and capturing the mouse click by listener.

I removed the runnable in the previous class and just used my main as the runnable. I was thinking about adding a cardlayout, but I wanted to remove my current jframe for aesthetics.

Sorry I got you so frustrated, I was just looking for help. I haven't been doing this that long, and I get some things confused. I found out the problem I was running into was the communication between the view, model and controller.

Thanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!