Thread View: borland.public.jbuilder.java.language
5 messages
5 total messages
Started by Thomas Arend
Sun, 01 May 2005 14:55
Professional usage of Swing
Author: Thomas Arend
Date: Sun, 01 May 2005 14:55
Date: Sun, 01 May 2005 14:55
25 lines
2021 bytes
2021 bytes
I have once again one of these questions dealing with the professional usage of the advices of school-books about java. So here it is: I try to implement an application, that in the whole manipulates a certain class A. That means every action in the gui is to manipulate a central object OA. I have implemented the manipulation of the object OA in an apllication that can to be used on the command-line. Now I would like to use swing-components. And here the problem comes up: In which class (extended from a Swing component) do I now create the central object? Is it the "main" part, where I normally would only create the Jframe an call "frame.show"; is it in the JFrame-constructor or is it in the content Pane in the JPanel, where I also implement the Buttons, menues and so on? And how do I make the central object known to all components of the GUI (in other words: Where do I implement the call of the methods of the class to manipulate the object for example after pressing a Button?) A long question, but as I said: My books only tell me where it is posible, but not what is best. Thanks Thomas
Re: Professional usage of Swing
Author: Alexey N. Solofnenko
Date: Mon, 02 May 2005 16:09
Date: Mon, 02 May 2005 16:09
34 lines
2245 bytes
2245 bytes
If I understood your question correctly.... I usually add method initWith(SomeObject obj) method that I call just after a form is created. - Alexey. Thomas Arend wrote: > I have once again one of these questions dealing with the professional usage > of the advices of school-books about java. > So here it is: > I try to implement an application, that in the whole manipulates a certain > class A. That means every action in the gui is to manipulate a central > object OA. > I have implemented the manipulation of the object OA in an apllication that > can to be used on the command-line. > > Now I would like to use swing-components. And here the problem comes up: In > which class (extended from a Swing component) do I now create the central > object? > Is it the "main" part, where I normally would only create the Jframe an call > "frame.show"; is it in the JFrame-constructor or is it in the content > Pane in the JPanel, where I also implement the Buttons, menues and so on? > > And how do I make the central object known to all components of the GUI > (in other words: Where do I implement the call of the methods of the class > to manipulate the object for example after pressing a Button?) > > A long question, but as I said: My books only tell me where it is posible, > but not what is best. > > Thanks > Thomas > > >
Re: Professional usage of Swing
Author: Thomas Arend
Date: Mon, 02 May 2005 20:40
Date: Mon, 02 May 2005 20:40
136 lines
4647 bytes
4647 bytes
As I have not quite understood your answer here is a simplyfied example and
perhaps you could tll me how to handle it::
public class A {
public A(){
// ...
}
public void methodOneOfA (){
/... <manipulates i in one way>
};
public void methodTwoOfA (){
/... <manipulates i in another way>
};
int i;
}
Now I would like to manipulate A:
1. way (command line method):
public class mainprog {
public mainprog() {
}
public static void main(String[] args) {
testobj = new A();
testobj.methodOneOfA();
testobj.methodTwoOfA();
}
A testobj;
}
As everything worked well, I would like to get the two methods as a result
of pressing seperate buttons in a swing-application.
Up to now I did it the following way:
class ButtonPanel extends JPanel implements ActionListener {
public ButtonPanel() {
FirstButton = new JButton("method1");
SecondButton = new JButton("method2");
add(FirstButton);
add(SecondButton);
FirstButton.addActionListener(this);
SecondButton.addActionListener(this);
testobj = new A();
}
public void actionPerformed (ActionEvent evt)
{
Object source = evt.getSource();
if (source == FirstButton)
testobj.methodOneOfA();
else if (source == SecondButton) testobj.methodTwoOfA();
}
}
private A testObj;
}
public class ButtonFrame extends JFrame {
public ButtonFrame() {
setSize(350,200);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}});
Container contentPane = getContentPane();
contentPane.add(new ButtonPanel());
}
}
public class mainprog {
public mainprog() {
}
public static void main(String[] args) {
JFrame frame = new ButtonFrame();
frame.show();
}
}
But I don't know if putting the main Obj in the class ButtonPanel. Perhaps
it would be better to put it anywhere else, isn't it?
OK?
Thomas
"Alexey N. Solofnenko" <trelony@mail.ru> schrieb im Newsbeitrag
news:427650ba$1@newsgroups.borland.com...
> If I understood your question correctly.... I usually add method
> initWith(SomeObject obj) method that I call just after a form is created.
>
> - Alexey.
>
> Thomas Arend wrote:
> > I have once again one of these questions dealing with the professional
usage
> > of the advices of school-books about java.
> > So here it is:
> > I try to implement an application, that in the whole manipulates a
certain
> > class A. That means every action in the gui is to manipulate a central
> > object OA.
> > I have implemented the manipulation of the object OA in an apllication
that
> > can to be used on the command-line.
> >
> > Now I would like to use swing-components. And here the problem comes up:
In
> > which class (extended from a Swing component) do I now create the
central
> > object?
> > Is it the "main" part, where I normally would only create the Jframe an
call
> > "frame.show"; is it in the JFrame-constructor or is it in the content
> > Pane in the JPanel, where I also implement the Buttons, menues and so
on?
> >
> > And how do I make the central object known to all components of the GUI
> > (in other words: Where do I implement the call of the methods of the
class
> > to manipulate the object for example after pressing a Button?)
> >
> > A long question, but as I said: My books only tell me where it is
posible,
> > but not what is best.
> >
> > Thanks
> > Thomas
> >
> >
> >
Re: Professional usage of Swing
Author: Alexey N. Solofnenko
Date: Mon, 02 May 2005 20:48
Date: Mon, 02 May 2005 20:48
170 lines
5441 bytes
5441 bytes
Well, I guess I was close to what you need. You can put your object into
Application class and into button panel. For that I usually define an
extra method (like "initWith(A obj)") to set the object reference in GUI
components.
It also looks like you do not use JBuilder's GUI designer and type
actions manually. It is much easier to use the designer - it will
generate necessary code itself.
- Alexey.
Thomas Arend wrote:
> As I have not quite understood your answer here is a simplyfied example and
> perhaps you could tll me how to handle it::
>
>
> public class A {
> public A(){
>
> // ...
> }
> public void methodOneOfA (){
> /... <manipulates i in one way>
> };
> public void methodTwoOfA (){
> /... <manipulates i in another way>
> };
> int i;
> }
>
> Now I would like to manipulate A:
> 1. way (command line method):
>
> public class mainprog {
> public mainprog() {
> }
> public static void main(String[] args) {
> testobj = new A();
> testobj.methodOneOfA();
> testobj.methodTwoOfA();
> }
> A testobj;
> }
>
> As everything worked well, I would like to get the two methods as a result
> of pressing seperate buttons in a swing-application.
> Up to now I did it the following way:
> class ButtonPanel extends JPanel implements ActionListener {
> public ButtonPanel() {
> FirstButton = new JButton("method1");
> SecondButton = new JButton("method2");
>
> add(FirstButton);
> add(SecondButton);
>
> FirstButton.addActionListener(this);
> SecondButton.addActionListener(this);
> testobj = new A();
> }
> public void actionPerformed (ActionEvent evt)
> {
> Object source = evt.getSource();
> if (source == FirstButton)
> testobj.methodOneOfA();
> else if (source == SecondButton) testobj.methodTwoOfA();
> }
>
> }
> private A testObj;
> }
>
> public class ButtonFrame extends JFrame {
> public ButtonFrame() {
> setSize(350,200);
> addWindowListener(new WindowAdapter(){
> public void windowClosing(WindowEvent e){
> System.exit(0);
> }});
> Container contentPane = getContentPane();
> contentPane.add(new ButtonPanel());
> }
> }
> public class mainprog {
> public mainprog() {
> }
> public static void main(String[] args) {
>
> JFrame frame = new ButtonFrame();
> frame.show();
> }
> }
>
>
>
> But I don't know if putting the main Obj in the class ButtonPanel. Perhaps
> it would be better to put it anywhere else, isn't it?
>
> OK?
>
> Thomas
>
>
>
> "Alexey N. Solofnenko" <trelony@mail.ru> schrieb im Newsbeitrag
> news:427650ba$1@newsgroups.borland.com...
>
>>If I understood your question correctly.... I usually add method
>>initWith(SomeObject obj) method that I call just after a form is created.
>>
>>- Alexey.
>>
>>Thomas Arend wrote:
>>
>>>I have once again one of these questions dealing with the professional
>
> usage
>
>>>of the advices of school-books about java.
>>>So here it is:
>>>I try to implement an application, that in the whole manipulates a
>
> certain
>
>>>class A. That means every action in the gui is to manipulate a central
>>>object OA.
>>>I have implemented the manipulation of the object OA in an apllication
>
> that
>
>>>can to be used on the command-line.
>>>
>>>Now I would like to use swing-components. And here the problem comes up:
>
> In
>
>>>which class (extended from a Swing component) do I now create the
>
> central
>
>>>object?
>>>Is it the "main" part, where I normally would only create the Jframe an
>
> call
>
>>>"frame.show"; is it in the JFrame-constructor or is it in the content
>>>Pane in the JPanel, where I also implement the Buttons, menues and so
>
> on?
>
>>>And how do I make the central object known to all components of the GUI
>>>(in other words: Where do I implement the call of the methods of the
>
> class
>
>>>to manipulate the object for example after pressing a Button?)
>>>
>>>A long question, but as I said: My books only tell me where it is
>
> posible,
>
>>>but not what is best.
>>>
>>>Thanks
>>>Thomas
>>>
>>>
>>>
>
>
>
Re: Professional usage of Swing
Author: Thomas Arend
Date: Mon, 02 May 2005 21:00
Date: Mon, 02 May 2005 21:00
187 lines
6143 bytes
6143 bytes
I think I understood,
next time I will use the GUI Designer, but a freind of mine told me about
some difficulties with it, so i first tried without.
Could you (to be shure if I understood you right, just put your code in
mine, so that I find out what you meant by the initWith mehtod. In which
class would you implement it?
Thanks Thomas
"Alexey N. Solofnenko" <trelony@mail.ru> schrieb im Newsbeitrag
news:4276922d$1@newsgroups.borland.com...
> Well, I guess I was close to what you need. You can put your object into
> Application class and into button panel. For that I usually define an
> extra method (like "initWith(A obj)") to set the object reference in GUI
> components.
>
> It also looks like you do not use JBuilder's GUI designer and type
> actions manually. It is much easier to use the designer - it will
> generate necessary code itself.
>
> - Alexey.
>
> Thomas Arend wrote:
> > As I have not quite understood your answer here is a simplyfied example
and
> > perhaps you could tll me how to handle it::
> >
> >
> > public class A {
> > public A(){
> >
> > // ...
> > }
> > public void methodOneOfA (){
> > /... <manipulates i in one way>
> > };
> > public void methodTwoOfA (){
> > /... <manipulates i in another way>
> > };
> > int i;
> > }
> >
> > Now I would like to manipulate A:
> > 1. way (command line method):
> >
> > public class mainprog {
> > public mainprog() {
> > }
> > public static void main(String[] args) {
> > testobj = new A();
> > testobj.methodOneOfA();
> > testobj.methodTwoOfA();
> > }
> > A testobj;
> > }
> >
> > As everything worked well, I would like to get the two methods as a
result
> > of pressing seperate buttons in a swing-application.
> > Up to now I did it the following way:
> > class ButtonPanel extends JPanel implements ActionListener {
> > public ButtonPanel() {
> > FirstButton = new JButton("method1");
> > SecondButton = new JButton("method2");
> >
> > add(FirstButton);
> > add(SecondButton);
> >
> > FirstButton.addActionListener(this);
> > SecondButton.addActionListener(this);
> > testobj = new A();
> > }
> > public void actionPerformed (ActionEvent evt)
> > {
> > Object source = evt.getSource();
> > if (source == FirstButton)
> > testobj.methodOneOfA();
> > else if (source == SecondButton) testobj.methodTwoOfA();
> > }
> >
> > }
> > private A testObj;
> > }
> >
> > public class ButtonFrame extends JFrame {
> > public ButtonFrame() {
> > setSize(350,200);
> > addWindowListener(new WindowAdapter(){
> > public void windowClosing(WindowEvent e){
> > System.exit(0);
> > }});
> > Container contentPane = getContentPane();
> > contentPane.add(new ButtonPanel());
> > }
> > }
> > public class mainprog {
> > public mainprog() {
> > }
> > public static void main(String[] args) {
> >
> > JFrame frame = new ButtonFrame();
> > frame.show();
> > }
> > }
> >
> >
> >
> > But I don't know if putting the main Obj in the class ButtonPanel.
Perhaps
> > it would be better to put it anywhere else, isn't it?
> >
> > OK?
> >
> > Thomas
> >
> >
> >
> > "Alexey N. Solofnenko" <trelony@mail.ru> schrieb im Newsbeitrag
> > news:427650ba$1@newsgroups.borland.com...
> >
> >>If I understood your question correctly.... I usually add method
> >>initWith(SomeObject obj) method that I call just after a form is
created.
> >>
> >>- Alexey.
> >>
> >>Thomas Arend wrote:
> >>
> >>>I have once again one of these questions dealing with the professional
> >
> > usage
> >
> >>>of the advices of school-books about java.
> >>>So here it is:
> >>>I try to implement an application, that in the whole manipulates a
> >
> > certain
> >
> >>>class A. That means every action in the gui is to manipulate a central
> >>>object OA.
> >>>I have implemented the manipulation of the object OA in an apllication
> >
> > that
> >
> >>>can to be used on the command-line.
> >>>
> >>>Now I would like to use swing-components. And here the problem comes
up:
> >
> > In
> >
> >>>which class (extended from a Swing component) do I now create the
> >
> > central
> >
> >>>object?
> >>>Is it the "main" part, where I normally would only create the Jframe an
> >
> > call
> >
> >>>"frame.show"; is it in the JFrame-constructor or is it in the content
> >>>Pane in the JPanel, where I also implement the Buttons, menues and so
> >
> > on?
> >
> >>>And how do I make the central object known to all components of the GUI
> >>>(in other words: Where do I implement the call of the methods of the
> >
> > class
> >
> >>>to manipulate the object for example after pressing a Button?)
> >>>
> >>>A long question, but as I said: My books only tell me where it is
> >
> > posible,
> >
> >>>but not what is best.
> >>>
> >>>Thanks
> >>>Thomas
> >>>
> >>>
> >>>
> >
> >
> >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads