Skip to main content



      Home
Home » Archived » Visual Editor (VE) » Display manually coded visual elements
Display manually coded visual elements [message #12348] Fri, 19 December 2003 17:40 Go to next message
Eclipse UserFriend
Originally posted by: geo_mc5.yahoo.de

Hi all,
VE is working fine for me when I create a new visual element (eg. JButton)
through the VE engine. But when I tried to visualise a JFrame and its
contents that I had written "by hand" before I get a blank screen even
though I had opened the class with the "Visual Editor". (When I run the
class everything is fine!)

Am I doing something wrong? My own code is of course different from code
generated by the VE - but is this the reason that my code is not
visualised?

Regards,

Georg

Here is the code, some of it is in German but don't bother...
------------------
/**
*
*/
import javax.swing.*;
import java.awt.*;

public class StartDlg extends JFrame {

public static void main(String[] args) {
StartDlg startdialog = new StartDlg();
}

public StartDlg() {

super();

final int MAXRECHENTIEFE = 50;

JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JRadioButton rbA1 = new JRadioButton("Mensch");
JRadioButton rbA2 = new JRadioButton("Lokaler Computer Strategie 1");
JRadioButton rbA3 = new JRadioButton("Lokaler Computer Strategie 2");
JRadioButton rbA4 = new JRadioButton("Zuggeneratorserver 1");
JRadioButton rbA5 = new JRadioButton("Zuggeneratorserver 2");
JTextField tfIPA = new JTextField("0.0.0.0");
JTextField tfPortA = new JTextField("7888");

JRadioButton rbB1 = new JRadioButton("Mensch");
JRadioButton rbB2 = new JRadioButton("Lokaler Computer Strategie 1");
JRadioButton rbB3 = new JRadioButton("Lokaler Computer Strategie 2");
JRadioButton rbB4 = new JRadioButton("Zuggeneratorserver 1");
JRadioButton rbB5 = new JRadioButton("Zuggeneratorserver 2");
JTextField tfIPB = new JTextField("0.0.0.0");
JTextField tfPortB = new JTextField("7888");

JButton buttonOK = new JButton("OK");
JButton buttonCancel = new JButton("Cancel");

// Radio-Buttons auf die ButtonGroup setzen
ButtonGroup bgA = new ButtonGroup();
bgA.add(rbA1);
bgA.add(rbA2);
bgA.add(rbA3);
bgA.add(rbA4);
bgA.add(rbA5);

ButtonGroup bgB = new ButtonGroup();
bgB.add(rbB1);
bgB.add(rbB2);
bgB.add(rbB3);
bgB.add(rbB4);
bgB.add(rbB5);

rbA1.setSelected(true);
rbB1.setSelected(true);

// Nummern-Spinner für Werte von 1 bis MAXRECHENTIEFE, in 1 Schritten
JSpinner spA =
new JSpinner(new SpinnerNumberModel(1, 1, MAXRECHENTIEFE, 1));
JSpinner spB =
new JSpinner(new SpinnerNumberModel(1, 1, MAXRECHENTIEFE, 1));

Container c = frame.getContentPane();
c.setLayout(new GridLayout(16, 2, 30, 5));
c.add(new JLabel("Spieler A"));
c.add(new JLabel("Spieler B"));
c.add(rbA1);
c.add(rbB1);
c.add(rbA2);
c.add(rbB2);
c.add(rbA3);
c.add(rbB3);
c.add(rbA4);
c.add(rbB4);
c.add(rbA5);
c.add(rbB5);

c.add(new JLabel(" IP des Zuggeneratorservers:"));
c.add(new JLabel(" IP des Zuggeneratorservers:"));
c.add(tfIPA);
c.add(tfIPB);
c.add(new JLabel(" Port des Zuggeneratorservers:"));
c.add(new JLabel(" Port des Zuggeneratorservers:"));
c.add(tfPortA);
c.add(tfPortB);

c.add(new JLabel(" Rechentiefe bei Nicht-Mensch:"));
c.add(new JLabel(" Rechentiefe bei Nicht-Mensch:"));
c.add(spA);
c.add(spB);

c.add(buttonOK);
c.add(buttonCancel);

frame.pack();
frame.show();
}
}
Re: Display manually coded visual elements [message #12376 is a reply to message #12348] Sat, 20 December 2003 08:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi Georg,

> Am I doing something wrong? My own code is of course different from code
> generated by the VE - but is this the reason that my code is not
> visualised?

What occurs when the VE opens is that it parses the code to look for patterns and from
this it constructs a model of the Java components, their properties and relationships, and
this is what drives the GUI, tree, property sheet, etc... There is an article that
describes these patterns at
http://www-106.ibm.com/developerworks/websphere/library/tech articles/0303_winchester/winchester.html,
although this was written in February and there have been enhancements made since.
However the basic concepts in the article should still hold true.

Looking at your code there were a few changes required to make it VE parseable.

1 - Initialization should not occur during the constructor as you did. Instead we
look for a specific method that by default is initialize() although you can add new ones
using the Visual Editor preferences.
2 - The contentPane should be explicitly defined in its own field. We don't support
an implicit content pane right now as you coded.
3 - Every Java component needs its own field. We do have a line item to support the
kind of coding pattern you have where fields are just defined locally in methods as this
is a common coding pattern, especially for JLabel and other literals.
4 - For the JSpinner you referenced the static private field MAXRECHENTIEFE in their
construction. Right now we don't support this, although if this were on a separate class
as a static public field we would, i.e. if it is something we can find from reflection on
another type.

I re-wrote your class as below and this seems to parse and open OK in the VE.

Patterns for code parsing is one of the line items that needs to be worked on for a future
release, because the goal of the VE is that it is more flexible with the type of code it
can consume.

Best regards,

Joe

---------------

import javax.swing.*;
import java.awt.*;

public class StartDlg extends JFrame {

private JPanel c;
private JRadioButton rbA1;
private JRadioButton rbA2;
private JRadioButton rbA3;
private JRadioButton rbA4;
private JRadioButton rbA5;
private JTextField tfIPA;
private JTextField tfPortA;
private JRadioButton rbB1;
private JRadioButton rbB2;
private JRadioButton rbB3;
private JRadioButton rbB4;
private JRadioButton rbB5;
private JTextField tfIPB;
private JTextField tfPortB;
private JButton buttonOK;
private JButton buttonCancel;
private JSpinner spA;
private JSpinner spB;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JLabel lbl4;
private JLabel lbl5;
private JLabel lbl6;

public static void main(String[] args) {
StartDlg startdialog = new StartDlg();
}

public StartDlg() {
initialize();
}
private void initialize() {

final int MAXRECHENTIEFE = 50;

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

rbA1 = new JRadioButton("Mensch");
rbA2 = new JRadioButton("Lokaler Computer Strategie 1");
rbA3 = new JRadioButton("Lokaler Computer Strategie 2");
rbA4 = new JRadioButton("Zuggeneratorserver 1");
rbA5 = new JRadioButton("Zuggeneratorserver 2");
tfIPA = new JTextField("0.0.0.0");
tfPortA = new JTextField("7888");

rbB1 = new JRadioButton("Mensch");
rbB2 = new JRadioButton("Lokaler Computer Strategie 1");
rbB3 = new JRadioButton("Lokaler Computer Strategie 2");
rbB4 = new JRadioButton("Zuggeneratorserver 1");
rbB5 = new JRadioButton("Zuggeneratorserver 2");
tfIPB = new JTextField("0.0.0.0");
tfPortB = new JTextField("7888");

buttonOK = new JButton("OK");
buttonCancel = new JButton("Cancel");

// Radio-Buttons auf die ButtonGroup setzen
ButtonGroup bgA = new ButtonGroup();
bgA.add(rbA1);
bgA.add(rbA2);
bgA.add(rbA3);
bgA.add(rbA4);
bgA.add(rbA5);

ButtonGroup bgB = new ButtonGroup();
bgB.add(rbB1);
bgB.add(rbB2);
bgB.add(rbB3);
bgB.add(rbB4);
bgB.add(rbB5);

rbA1.setSelected(true);
rbB1.setSelected(true);

// Nummern-Spinner für Werte von 1 bis MAXRECHENTIEFE, in 1 Schritten
spA =
new JSpinner(new SpinnerNumberModel(1, 1, MAXRECHENTIEFE, 1));
spB =
new JSpinner(new SpinnerNumberModel(1, 1, MAXRECHENTIEFE, 1));

c = new JPanel();
setContentPane(c);
c.setLayout(new GridLayout(16, 2, 30, 5));
c.add(new JLabel("Spieler A"));
c.add(new JLabel("Spieler B"));
c.add(rbA1);
c.add(rbB1);
c.add(rbA2);
c.add(rbB2);
c.add(rbA3);
c.add(rbB3);
c.add(rbA4);
c.add(rbB4);
c.add(rbA5);
c.add(rbB5);
lbl1 = new JLabel(" IP des Zuggeneratorservers:");
c.add(lbl1);
lbl2 = new JLabel(" IP des Zuggeneratorservers:");
c.add(lbl2);
c.add(tfIPA);
c.add(tfIPB);
lbl3 = new JLabel(" Port des Zuggeneratorservers:");
c.add(lbl3);
lbl4 = new JLabel(" Port des Zuggeneratorservers:");
c.add(lbl4);
c.add(tfPortA);
c.add(tfPortB);
lbl5 = new JLabel(" Rechentiefe bei Nicht-Mensch:");
c.add(lbl5);
lbl6 = new JLabel(" Rechentiefe bei Nicht-Mensch:");
c.add(lbl6);
c.add(spA);
c.add(spB);

c.add(buttonOK);
c.add(buttonCancel);

this.pack();
this.show();
}
}
Thanks! (nt) [message #12385 is a reply to message #12376] Sun, 21 December 2003 18:43 Go to previous message
Eclipse UserFriend
Originally posted by: geo_mc5.yahoo.de

Thanks!
Georg
Re: Display manually coded visual elements [message #575863 is a reply to message #12348] Sat, 20 December 2003 08:49 Go to previous message
Eclipse UserFriend
Hi Georg,

> Am I doing something wrong? My own code is of course different from code
> generated by the VE - but is this the reason that my code is not
> visualised?

What occurs when the VE opens is that it parses the code to look for patterns and from
this it constructs a model of the Java components, their properties and relationships, and
this is what drives the GUI, tree, property sheet, etc... There is an article that
describes these patterns at
http://www-106.ibm.com/developerworks/websphere/library/tech articles/0303_winchester/winchester.html,
although this was written in February and there have been enhancements made since.
However the basic concepts in the article should still hold true.

Looking at your code there were a few changes required to make it VE parseable.

1 - Initialization should not occur during the constructor as you did. Instead we
look for a specific method that by default is initialize() although you can add new ones
using the Visual Editor preferences.
2 - The contentPane should be explicitly defined in its own field. We don't support
an implicit content pane right now as you coded.
3 - Every Java component needs its own field. We do have a line item to support the
kind of coding pattern you have where fields are just defined locally in methods as this
is a common coding pattern, especially for JLabel and other literals.
4 - For the JSpinner you referenced the static private field MAXRECHENTIEFE in their
construction. Right now we don't support this, although if this were on a separate class
as a static public field we would, i.e. if it is something we can find from reflection on
another type.

I re-wrote your class as below and this seems to parse and open OK in the VE.

Patterns for code parsing is one of the line items that needs to be worked on for a future
release, because the goal of the VE is that it is more flexible with the type of code it
can consume.

Best regards,

Joe

---------------

import javax.swing.*;
import java.awt.*;

public class StartDlg extends JFrame {

private JPanel c;
private JRadioButton rbA1;
private JRadioButton rbA2;
private JRadioButton rbA3;
private JRadioButton rbA4;
private JRadioButton rbA5;
private JTextField tfIPA;
private JTextField tfPortA;
private JRadioButton rbB1;
private JRadioButton rbB2;
private JRadioButton rbB3;
private JRadioButton rbB4;
private JRadioButton rbB5;
private JTextField tfIPB;
private JTextField tfPortB;
private JButton buttonOK;
private JButton buttonCancel;
private JSpinner spA;
private JSpinner spB;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JLabel lbl4;
private JLabel lbl5;
private JLabel lbl6;

public static void main(String[] args) {
StartDlg startdialog = new StartDlg();
}

public StartDlg() {
initialize();
}
private void initialize() {

final int MAXRECHENTIEFE = 50;

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

rbA1 = new JRadioButton("Mensch");
rbA2 = new JRadioButton("Lokaler Computer Strategie 1");
rbA3 = new JRadioButton("Lokaler Computer Strategie 2");
rbA4 = new JRadioButton("Zuggeneratorserver 1");
rbA5 = new JRadioButton("Zuggeneratorserver 2");
tfIPA = new JTextField("0.0.0.0");
tfPortA = new JTextField("7888");

rbB1 = new JRadioButton("Mensch");
rbB2 = new JRadioButton("Lokaler Computer Strategie 1");
rbB3 = new JRadioButton("Lokaler Computer Strategie 2");
rbB4 = new JRadioButton("Zuggeneratorserver 1");
rbB5 = new JRadioButton("Zuggeneratorserver 2");
tfIPB = new JTextField("0.0.0.0");
tfPortB = new JTextField("7888");

buttonOK = new JButton("OK");
buttonCancel = new JButton("Cancel");

// Radio-Buttons auf die ButtonGroup setzen
ButtonGroup bgA = new ButtonGroup();
bgA.add(rbA1);
bgA.add(rbA2);
bgA.add(rbA3);
bgA.add(rbA4);
bgA.add(rbA5);

ButtonGroup bgB = new ButtonGroup();
bgB.add(rbB1);
bgB.add(rbB2);
bgB.add(rbB3);
bgB.add(rbB4);
bgB.add(rbB5);

rbA1.setSelected(true);
rbB1.setSelected(true);

// Nummern-Spinner für Werte von 1 bis MAXRECHENTIEFE, in 1 Schritten
spA =
new JSpinner(new SpinnerNumberModel(1, 1, MAXRECHENTIEFE, 1));
spB =
new JSpinner(new SpinnerNumberModel(1, 1, MAXRECHENTIEFE, 1));

c = new JPanel();
setContentPane(c);
c.setLayout(new GridLayout(16, 2, 30, 5));
c.add(new JLabel("Spieler A"));
c.add(new JLabel("Spieler B"));
c.add(rbA1);
c.add(rbB1);
c.add(rbA2);
c.add(rbB2);
c.add(rbA3);
c.add(rbB3);
c.add(rbA4);
c.add(rbB4);
c.add(rbA5);
c.add(rbB5);
lbl1 = new JLabel(" IP des Zuggeneratorservers:");
c.add(lbl1);
lbl2 = new JLabel(" IP des Zuggeneratorservers:");
c.add(lbl2);
c.add(tfIPA);
c.add(tfIPB);
lbl3 = new JLabel(" Port des Zuggeneratorservers:");
c.add(lbl3);
lbl4 = new JLabel(" Port des Zuggeneratorservers:");
c.add(lbl4);
c.add(tfPortA);
c.add(tfPortB);
lbl5 = new JLabel(" Rechentiefe bei Nicht-Mensch:");
c.add(lbl5);
lbl6 = new JLabel(" Rechentiefe bei Nicht-Mensch:");
c.add(lbl6);
c.add(spA);
c.add(spB);

c.add(buttonOK);
c.add(buttonCancel);

this.pack();
this.show();
}
}
Thanks! (nt) [message #575903 is a reply to message #12376] Sun, 21 December 2003 18:43 Go to previous message
Eclipse UserFriend
Thanks!
Georg
Previous Topic:Is there a way to make Swing with Windows look and feel use system font settings from display proper
Next Topic:Creating a new Visual Class
Goto Forum:
  


Current Time: Sun Apr 27 02:55:57 EDT 2025

Powered by FUDForum. Page generated in 0.02864 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top