File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

swing questions

 
Greg Walker
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. How do you format buttons, fields, areas, etc... to been seen where you want them in the container?

2.When running a program with a GUI class and a backcode class of methods to manipulate data, how do you keep from having to constantly instantiate new instances of the classes while being able to access their methods?
 
Paul Clapham
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Greg Walker:
1. How do you format buttons, fields, areas, etc... to been seen where you want them in the container?
You use layout managers to control where components go. Here is a link to part of the Swing tutorial that talks about that.
2.When running a program with a GUI class and a backcode class of methods to manipulate data, how do you keep from having to constantly instantiate new instances of the classes while being able to access their methods?
It's hard to understand what you mean by that. Normally the reason you'd want to access the method of an instance is because you want to get information from the instance or you want to affect its state. If you want to do that repeatedly, then keep a reference to the object.
[ September 19, 2006: Message edited by: Paul Clapham ]
 
Greg Walker
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
It's hard to understand what you mean by that. Normally the reason you'd want to access the method of an instance is because you want to get information from the instance or you want to affect its state. If you want to do that repeatedly, then keep a reference to the object.

[ September 19, 2006: Message edited by: Paul Clapham ]


What I mean is in my GUI class when a user presses the "GO!" button that calls a method located in the BackCode class. The BackCode class then, for example, opens a file and displays that info in a textArea located in GUI class. To access the GUI class I need to have an instance of it. Every time I declare an instance it creates a whole new containier and I wind up with 20 containers after 20 button presses.

When I try to declare a global variable in the BackCode class my GUI freaks out and crashes.
[ September 19, 2006: Message edited by: Greg Walker ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> When I try to declare a global variable in the BackCode class my GUI freaks out and crashes.

from your description, here's a simple demo
click the button to update the textArea with the data (in this case random numbers)

 
Greg Walker
Greenhorn
Posts: 24
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well that's just one example. What if I want to activate an option pane from teh BackCode class. The way I ahve it set up is in GUIclass there is a method

example: public void subscribeFailed(String newsgroup) {
//display option pane that says subscription failed
}

But to call that I need an instance of GUIclass...
GUIclass object = new GUIclass();

...to call the method to display the option pane

object.subscribeFailed("sci.physics");

The instantiation creates a brand new container (JFrame) every time it's created. So usually to avoid having to keep creating objects we declare them globably so all the methods can use them, but when I do this I get a initiation error message at the terminal prompt and it keeps displaying it as if in an infinite loop.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Well that's just one example.

notice how you were able to copy/paste/compile/run and see how it all fit together.

now it's your turn.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic