Design problem with Swing

Hi all. I've run into some design problems when trying to create a Swing app.
I've got a non-graphical class that emulates a power supply unit. Let's call it PSUnit. I have to create a GUI for PSUnit.
Every class designed to build a full GUI app uses PSUnit in some way (changes its voltage, displays voltage, turns it on, turns it off, etc.)
Here's the catch. Suppose I've got a class:
public class BuildingBlock extends JPanel {
     // code includes a JTextBox displaying
     // the current PSUnit voltage.
}another class is created for setting the voltage:
public class AnotherBlock extends JPanel {
     // this class contains a JSpinner and
     // a button that retrieves the JSpinner value
     // and sets it as the current voltage of
     // PSUnit
}When the button in AnotherBlock is clicked, I must notify the BuildingBlock class that a PSUnit has changed its state so it can update it's values and display the correct data.
I've tried to do this a few times but failed miserably, so I'm hoping you guys could help me out.
Please note that both of the above classes have some additional code and it's not very pleasant to make one class an inner class of another. I should be able to create a "standalone" classes which, combined together, form a GUI for PSUnit.
Thanks.

Yes this is a common problem that many of us have when building UIs
Here's the question: In this instance, are these two classes really independant? Could they stand alone? Often when building a GUI, it's not even that easy to answer that question, but these leads to the two ways you can solve this
#1. Make them independent, and use listeners either using Observable / Observer or creating your own custom listeners. The advantage of this is smaller classes and more independence. The disadvantage is it's generally more complicated, especially at the design stage
#2 (what I'd probably recommend). Make 1 GUI class "MyPSFrame", then declare your panel classes as inner classes within that class. This way, everything goes into one spot, and everything is shareable. This also makes sense if you can't have 1 of the panels without the other.

Similar Messages

  • Design problem with JScrollPane

    First, I have problems with english. I hope u understand without problems that Im trying to say here. Sorry about that.
    Mi problem is whit a JScrollPane. I want to put an image whit a predefined size for draw inside it. I dont have any information about it, just the size. I want to put it in a JPane. The best choice is use the JPane area. The problem is that I want to use a JScrollPane because the image is bigger that the visualization area.
    Im unable to put a Canvas in the ScrollPane, or a JPane whit a predefined size or an image whit a predefined size. Im sure that is a design problem. Somebody can tell me something I can start whit? What do u think is better choice to put inside a JScrollPane?
    I dont send any source code because I dont have anything else that is show in the example.
    Gracias.

    import java.awt.*;
    import javax.swing.*;
    import java.net.URL;
    public class Test extends JFrame {
      String url = "http://www.sandbox-usa.com/images/product_images/2piece_16.gif";
      public Test() {
    //    System.getProperties().put( "proxySet", "true" );  // uncomment if you have proxy
    //    System.getProperties().put( "proxyHost", "myproxy.mydomain.com" ); // Your proxyname/IP
    //    System.getProperties().put( "proxyPort", "80"); // Sometimes 8080   
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   
        Container content = getContentPane();
        try {
          Image i = Toolkit.getDefaultToolkit().getImage(new URL(url));
          JLabel jl = new JLabel(new ImageIcon(i));
          content.add(new JScrollPane(jl), BorderLayout.CENTER);
          setSize(200, 200);   
          setVisible(true); 
        } catch (Exception e) { e.printStackTrace(); }
      public static void main(String[] args) { new Test(); }
    }

  • Design Problem with GUI sub vi

    Hello community,
    in general, I would like to separate the GUI from the data, but I get
    a problem with this design approach in LabView:
    I often have sub VIs that are supposed to control something.
    Therefore, these VIs consist of a control loop. A GUI window should
    show the regulation process (showing how the tracking error is
    hopefully approaching zero etc.). As I said, this GUI should be a
    separate VI (separate from the control loop VI). Since the GUI has to
    be updated on each sample, it is clear that the GUI VI should be
    inside the control loop, and therefore, it should be a sub VI of the
    control loop VI.
    Now, the problem is that the control loop VI itsself is a sub VI
    because the whole regulation is just a subsystem of the whole program
    (The main VI doesn't have a GUI, but first starts a (GUI) input mask
    for the same reason: separate the GUI from the rest).
    But back to the GUI VI inside the control loop. I must check the 'Show
    Front Panel When Called' option. But I can't check the 'Close
    Afterwards if Originally Closed' option since the GUI VI would appear
    and disappear in the control loop - according to the loop's sample
    rate. However, if I don't check the 'Close Afterwards if Originally
    Closed' option then the GUI VI will continue to show, even after the
    control process is finished.
    So in other words: I need the possiblity to close the GUI VI
    programatically, after the control process is finished.
    Any ideas?
    Regards
    Johannes

    Hi tmh,
    thanks for your answer
    On Tue, 11 Nov 2003 10:26:32 -0600 (CST), tmh wrote:
    >I think you're on the wrong track trying to put your 'GUI VI' inside
    >your control loop. It might be a better design to have the control and
    >GUI handled by separate loops and use an appropriate method to pass
    >data between the two, e.g. a global variable to pass the setpoint from
    >GUI to control...
    I try to avoid globals. Now, suppose I had multiple unrelated control
    loops. I had to suppose a global variable for each of these
    subsystems. I already use globals for the GPIB device IDs. I wouldn't
    like more.
    >and a queue to pass readings from control to GUI. In
    >fact, you could even split the GUI into two loops: one to read user
    >input from the front pa
    nel controls and one to display data returned
    >by the control loop.
    But if I split the GUI: How can I view them simultaneously? The user
    must see input and output simultaneously, in one window.
    >You may find it's more convenient to make the GUI
    >the top-level VI and make the control loop a subVI of that (but
    >outside the GUI loops).
    Your approach sounds interesting. Is there a sample for this
    architecture in the examples?
    Anyway, I have to point out that I have several unrelated GUI windows
    in my application. There is no notion of a main GUI in my application.
    The control loop is just one feature of my application, so it doesn't
    make sense to use the control GUI as the top-level VI. At application
    startup a user input form is displayed (it also has some sort of menu
    selection). But even this window can't be toplevel since it provides
    an Option radio button (that shows and hides controls, accordingly) a
    CONTINUE button, and a STOP button which implies that the input
    form.vi must be
    in a loop.
    The problem is that I can't send messages to windows in LabView as I
    am used to in Win32/VC++.
    Johannes

  • Reporting designer - problem with insertin query

    hi, I have problem with inserting query into reporting designer, when i do it there occurs metadata error and the system write check query, but query is ok, there are no variables. Have you any idea whats the problem.
    thanx

    I had a similar problem after "upgrading" to SAPGUI 7.10, except my failure was in the BEx Analyzer. (We are still using BW 3.5 SP 18.)
    The solution I found was in SAP Note 1039191 which addresses this problem for both the Analyzer and the Query Designer, and includes a revised "wdbsPres.dll" file as a workaround. After downloading and installing this file, the problem was resolved.
    BTW, I have asked SAP when this will be fixed in a future FEP, but they have so far only given me a very ambiguous reply suggesting that I try it on another PC.
    Hope this helps...
    Bob

  • Design problem with the cube.

    hi,
         i need to maintain two fields in the cube, first field hold data month wise(like M1,M2,M3) and the second field hold the data in the year to month wise.
    eg.
                          M1          M2           M3
           FIELD1    10          20            30
           FIELD2    10          30            70
    PLEASE SUGGEST

    Hi LAX,
    I can think of following design:
    You have a source feeding the information as 10, 20, 30 etc for different months.
    Now continue loading data from source to cube for the first field (FIELD1).
    Now introduce an ODS between Cube and Source. Keep everything you have in cube as Key field in the ODS except Key Figure. keep the key Figure in the additive mode.
    Now in the start routine of ODS, for each of the record, you will have value of calmonth and a value to the KF.
    Say calmonth value is 01/2009 and KF value is 10. The thing you are doing is, you want to add this value to all the months along with the value of that month. Meaning this 10 should be included in all the months till december. Correct me if I am wrong.
    So for each of the record, duplicate the record from the calmonth to 12. In the case of example, it would be from 02 to 12 times.
    While duplicating the record, update the calmonth value of the duplicated data_package record as 02/2009, 03/2009 etc. etc.
    By doing this, you will have value for 10 for all the months in that year.
    After loading this information to ODS, you can pass that to Cube which will have your required numbers for FIELD2.
    - Danny

  • Resolution problems with Swing, MigLayout, and Substance.

    I've got some testers trying out my application on various systems. One computer is a Dell Mini and it is giving me some trouble with resolution. I am using MigLayout as the layout manager for every JPanel and for everything. I am also using Substance L & F. I thought this would be all I need to do to keep my application resolution independent. It appears that I have too many rows. The extra rows are getting cut off.
    I''ve edited my code and posted the relavent part of my code in the following post.

    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.text.NumberFormat;
    import javax.swing.*;
    import org.jvnet.substance.skin.SubstanceCremeCoffeeLookAndFeel;
    import net.miginfocom.swing.MigLayout;
    public class SiteInfoPanel extends JPanel{
        private JTextField swisNumber;
        private JTextField siteName;
        private JFormattedTextField lat;
        private JFormattedTextField lon;
        private JFormattedTextField openYear;
        private JFormattedTextField closeYear;
        private JFormattedTextField waste;
        private JFormattedTextField footprint;
        private JButton searchName;
        private JButton searchSWIS;
        private JLabel or1;
        private JLabel siteInfo;
        private JLabel swisNumberL;
        private JLabel nameL;
        private JLabel county;
        private JLabel latL;
        private JLabel lonL;
        private JLabel openYearL;
        private JLabel closeYearL;
        private JLabel wasteL;
        private JLabel footprintL;
        private JLabel searchBy;
        private JSeparator sep1;
        private JSeparator sep2;
        public SiteInfoPanel(){
            initComponents();
        private void initComponents(){
            swisNumber = new JTextField();
            swisNumber.setHorizontalAlignment(JTextField.CENTER);
            swisNumber.setColumns(25);
            siteName = new JTextField();
            siteName.setHorizontalAlignment(JTextField.CENTER);
            siteName.setColumns(40);
            NumberFormat yr = NumberFormat.getInstance();
            yr.setGroupingUsed(false);
            yr.setMaximumIntegerDigits(4);
            yr.setMaximumFractionDigits(0);
            NumberFormat loc = NumberFormat.getInstance();
            loc.setGroupingUsed(false);
            loc.setMaximumIntegerDigits(3);
            loc.setMaximumFractionDigits(2);
            NumberFormat rest = NumberFormat.getInstance();
            rest.setGroupingUsed(false);
            rest.setMaximumFractionDigits(2);
            rest.setMaximumIntegerDigits(9);
            lat = new JFormattedTextField(loc);
            lat.setColumns(8);
            lon = new JFormattedTextField(loc);
            lon.setColumns(8);
            openYear = new JFormattedTextField(yr);
            openYear.setColumns(4);
            closeYear = new JFormattedTextField(yr);
            closeYear.setColumns(4);
            waste = new JFormattedTextField(rest);
            waste.setColumns(10);
            footprint = new JFormattedTextField(rest);
            footprint.setColumns(10);
            swisNumberL = new JLabel("SWIS number:");
            nameL = new JLabel("Site name:");
            county = new JLabel();
            latL = new JLabel("Site Latitude: ");
            lonL = new JLabel("Site Longitude: ");
            openYearL = new JLabel("Opening Year");
            closeYearL = new JLabel("Closing Year");
            wasteL = new JLabel("Waste in place (tons)");
            footprintL = new JLabel("Site footprint (acres)");
            or1 = new JLabel("OR");
            siteInfo = new JLabel("Site Info:");
            siteInfo.setForeground(Color.blue);
            searchBy = new JLabel("Search for site by: ");
            searchBy.setForeground(Color.blue);
            sep1 = new JSeparator();
            sep2 = new JSeparator();
            searchName = new JButton("Search by name");
            searchSWIS = new JButton("Search by SWIS #");
            buildComponents();
        private void buildComponents(){
            this.setLayout(new MigLayout("wrap 4", "[grow]", "[]25[]"));
            this.add(searchBy, "span 4, split 2");
            this.add(sep1, "span 3, growx");
            this.add(swisNumberL, "right");
            this.add(swisNumber, "span 2, center");
            this.add(searchSWIS, "wrap");
            this.add(or1,"skip 3");
            this.add(nameL, "right");
            this.add(siteName,"span 2, center");
            this.add(searchName);
            this.add(county,"skip 1, right");
            this.add(new JLabel(" County"), "wrap");
            this.add(siteInfo, "span 5, split 2");
            this.add(sep2,"span 3, growx");
            this.add(latL,"right");
            this.add(lat, "wrap");
            this.add(lonL, "right");
            this.add(lon, "wrap");
            this.add(footprintL, "right");
            this.add(footprint, "wrap");
            this.add(new JLabel("BLAH"), "span 2, split 2");
            this.add(new JSeparator(), "growx, wrap");
            this.add(new JCheckBox("BLAH"), "center, wrap");
            this.add(openYearL,"right");
            this.add(openYear, "wrap");
            this.add(closeYearL, "right");
            this.add(closeYear, "wrap");
            this.add(wasteL,"right");
            this.add(waste, " wrap");
            this.setVisible(true);
        public static void main(String args[]){
            try {
                UIManager.setLookAndFeel(new SubstanceCremeCoffeeLookAndFeel());
            } catch (UnsupportedLookAndFeelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            EventQueue.invokeLater(new Runnable(){
                @Override
                public void run() {
                    JFrame f = new JFrame();
                    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    f.getContentPane().add(new SiteInfoPanel());
                    f.pack();
                    f.setVisible(true);
    }<!--
    @page { margin: 0.79in }
    P { margin-bottom: 0.08in }
    -->

  • Query designer problem with SAP GUI 7.10

    I recently installed the SAP GUI 7.10 and when I'm going to apply or remove a filter in any characteristic, this error is shown :
    <b>----
    BEx Query Designer
    Run-time error '-2147417848 (80010108)':
    Automation error
    The object invoked has disconnected from its clients.
    OK  
    </b>
    Anybody knows what to do?
    Tnks in advance.

    I had a similar problem after "upgrading" to SAPGUI 7.10, except my failure was in the BEx Analyzer. (We are still using BW 3.5 SP 18.)
    The solution I found was in SAP Note 1039191 which addresses this problem for both the Analyzer and the Query Designer, and includes a revised "wdbsPres.dll" file as a workaround. After downloading and installing this file, the problem was resolved.
    BTW, I have asked SAP when this will be fixed in a future FEP, but they have so far only given me a very ambiguous reply suggesting that I try it on another PC.
    Hope this helps...
    Bob

  • Newby has problems with swing - please help

    hi guys I'm sure this is easy for someone. My Program myTimeCalc.java fails to run with a nullpointerexception. I realise I am very new to this so if I'm doing something really stupid then hey its about time I learnt. So thanks in advance and any help greatly appreciated.
    import java.awt.*;
    import javax.swing.*;
    public class myTimeCalc extends JFrame {
        public myTimeCalc() {
            super("Time Calc");
            setSize(400,400);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            timeField time1 =new timeField();
            timeField time2 =new timeField();
            JPanel panel = new JPanel();
            panel.add(time1);
            panel.add(time2);
            add(panel);
            setVisible(true);
        } // myTimeCalc
        public class timeField extends JPanel {
            public int hours;
            public int mins;
            public hoursField txtHours;
            public minsField txtMins;
            public JLabel lab;
            public timeField() {
                hoursField txtHours = new hoursField();
                minsField txtMins= new minsField();
                JLabel lab = new JLabel(":");
                //txtHours.setText("0");
                //txtMins.setText("0");
                setTime(0,0);
                add(txtHours);
                add(lab);
                add(txtMins);
            } // timeField
            public void setTime(int inHours, int inMins) {
                hours = inHours;
                mins = inMins;
                txtHours.setText("" + inHours );
                txtMins.setText("" + inMins);
            public class hoursField extends JTextField {
                public hoursField() {
                    super(4);
            } // hoursField
            public class minsField extends JTextField {
                public minsField() {
                    super(2);
            } // minsField
        } // timeField
        public static void main(String[] args) {
            myTimeCalc mtc = new myTimeCalc();
    } // myTimeCalc

    Hi Phill.,
    I have altered your code. Just a little bit. take a look.
    Please do changes accordingly. And better use NetBeans IDE for developing a swing application.
    -sps. :)
    import java.awt.*;
    import javax.swing.*;
    public class myTimeCalc extends JFrame
         private JPanel panel;
        public myTimeCalc()
            //super("Time Calc");
            initComponents();
        } // myTimeCalc
        private void initComponents()
            setSize(400,400);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            timeField time1 =new timeField();
            timeField time2 =new timeField();
            panel = new JPanel();
            panel.add(time1);
            panel.add(time2);
            getContentPane().add(panel);
            pack();
            setVisible(true);
        public class timeField extends JPanel
            public int hours;
            public int mins;
            public hoursField txtHours;
            public minsField txtMins;
            public JLabel lab;
            public timeField()
                txtHours = new hoursField();   // your code is hoursField txtHours = new hoursField();  there is no need for hoursField in front of the variable txtHours coz you have already declared this variable is of type hoursField.
                txtMins= new minsField();
                lab = new JLabel(":");
                //txtHours.setText("0");
                //txtMins.setText("0");
                setTime(0,0);
                add(txtHours);
                add(lab);
                add(txtMins);
            } // timeField
            public void setTime(int inHours, int inMins)
                hours = inHours;
                mins = inMins;
                txtHours.setText("" + inHours );
                txtMins.setText("" + inMins);
            public class hoursField extends JTextField
                public hoursField()
                    super(4);
            } // hoursField
            public class minsField extends JTextField
                public minsField()
                    super(2);
            } // minsField
        } // timeField
        public static void main(String[] args)
            new myTimeCalc().show();
    } // myTimeCalc

  • Problems with swing, please help!!!

    im trying to display an image made up of a set of squares.
    i have a JFrame class which has the main method placing a JComponent into its Container using the getContentPane().add method.
    the JComponent class sets up the image using the paintComponent() method
    When i try to run the program all i get is a grey frame.
    Ive looked at other threads in this forum to fix my problem but it doesnt seem to fix it.
    any help is much appreciated.

    import java.awt.*;
    import java.awt.event.*;
    import java.util.EventListener;
    import javax.swing.*;
    import java.applet.*;
    public class Display extends JFrame
         protected DisCanvas canvas;
         protected EventListener listener;
         protected boolean isApplet = false;
         public Display(boolean isApplet)
              this.isApplet = isApplet;
              //setLayout(new BorderLayout());
         //     add(makeCanvas(), BorderLayout.CENTER);
         public Display()
              //this(true);
    canvas = new DisCanvas();
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(canvas, BorderLayout.CENTER);
    this.addWindowListener(new AppCloser());
    this.setSize(300, 300);
    this.setVisible(true);
    this.repaint();
    public static void main(String[] args)
    new Display();
    static class AppCloser extends WindowAdapter
              public void windowClosing(WindowEvent e)
                   System.exit(0);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.image.*;
    public class DisCanvas extends java.awt.Canvas
    Patch[] patchArray = new Patch[100];
    int width = 200;
    int height = 300;
    BufferedImage image;
    Graphics2D g2D;
    public DisCanvas()
    patchArray[0] = new Patch(0, 0, 20, 30); patchArray[10] = new Patch(0, 30, 20, 30);
    patchArray[1] = new Patch(20, 0, 20, 30); patchArray[11] = new Patch(20, 30, 20, 30);
    patchArray[2] = new Patch(40, 0, 20, 30); patchArray[12] = new Patch(40, 30, 20, 30);
    patchArray[3] = new Patch(60, 0, 20, 30); patchArray[13] = new Patch(60, 30, 20, 30);
    patchArray[4] = new Patch(80, 0, 20, 30); patchArray[14] = new Patch(80, 30, 20, 30);
    patchArray[5] = new Patch(100, 0, 20, 30); patchArray[15] = new Patch(100, 30, 20, 30);
    patchArray[6] = new Patch(120, 0, 20, 30); patchArray[16] = new Patch(120, 30, 20, 30);
    patchArray[7] = new Patch(140, 0, 20, 30); patchArray[17] = new Patch(140, 30, 20, 30);
    patchArray[8] = new Patch(160, 0, 20, 30); patchArray[18] = new Patch(160, 30, 20, 30);
    patchArray[9] = new Patch(180, 0, 20, 30); patchArray[19] = new Patch(180, 30, 20, 30);
    patchArray[20] = new Patch(0, 60, 20, 30); patchArray[30] = new Patch(0, 90, 20, 30);
    patchArray[21] = new Patch(20, 60, 20, 30); patchArray[31] = new Patch(20, 90, 20, 30);
    patchArray[22] = new Patch(40, 60, 20, 30); patchArray[32] = new Patch(40, 90, 20, 30);
    patchArray[23] = new Patch(60, 60, 20, 30); patchArray[33] = new Patch(60, 90, 20, 30);
    patchArray[24] = new Patch(80, 60, 20, 30); patchArray[34] = new Patch(80, 90, 20, 30);
    patchArray[25] = new Patch(100, 60, 20, 30); patchArray[35] = new Patch(100, 90, 20, 30);
    patchArray[26] = new Patch(120, 60, 20, 30); patchArray[36] = new Patch(120, 90, 20, 30);
    patchArray[27] = new Patch(140, 60, 20, 30); patchArray[37] = new Patch(140, 90, 20, 30);
    patchArray[28] = new Patch(160, 60, 20, 30); patchArray[38] = new Patch(160, 90, 20, 30);
    patchArray[29] = new Patch(180, 60, 20, 30); patchArray[39] = new Patch(180, 90, 20, 30);
    patchArray[40] = new Patch(0, 120, 20, 30); patchArray[50] = new Patch(0, 150, 20, 30);
    patchArray[41] = new Patch(20, 120, 20, 30); patchArray[51] = new Patch(20, 150, 20, 30);
    patchArray[42] = new Patch(40, 120, 20, 30); patchArray[52] = new Patch(40, 150, 20, 30);
    patchArray[43] = new Patch(60, 120, 20, 30); patchArray[53] = new Patch(60, 150, 20, 30);
    patchArray[44] = new Patch(80, 120, 20, 30); patchArray[54] = new Patch(80, 150, 20, 30);
    patchArray[45] = new Patch(100, 120, 20, 30); patchArray[55] = new Patch(100, 150, 20, 30);
    patchArray[46] = new Patch(120, 120, 20, 30); patchArray[56] = new Patch(120, 150, 20, 30);
    patchArray[47] = new Patch(140, 120, 20, 30); patchArray[57] = new Patch(140, 150, 20, 30);
    patchArray[48] = new Patch(160, 120, 20, 30); patchArray[58] = new Patch(160, 150, 20, 30);
    patchArray[49] = new Patch(180, 120, 20, 30); patchArray[59] = new Patch(180, 150, 20, 30);
    patchArray[60] = new Patch(0, 180, 20, 30); patchArray[70] = new Patch(0, 210, 20, 30);
    patchArray[61] = new Patch(20, 180, 20, 30); patchArray[71] = new Patch(20, 210, 20, 30);
    patchArray[62] = new Patch(40, 180, 20, 30); patchArray[72] = new Patch(40, 210, 20, 30);
    patchArray[63] = new Patch(60, 180, 20, 30); patchArray[73] = new Patch(60, 210, 20, 30);
    patchArray[64] = new Patch(80, 180, 20, 30); patchArray[74] = new Patch(80, 210, 20, 30);
    patchArray[65] = new Patch(100, 180, 20, 30); patchArray[75] = new Patch(100, 210, 20, 30);
    patchArray[66] = new Patch(120, 180, 20, 30); patchArray[76] = new Patch(120, 210, 20, 30);
    patchArray[67] = new Patch(140, 180, 20, 30); patchArray[77] = new Patch(140, 210, 20, 30);
    patchArray[68] = new Patch(160, 180, 20, 30); patchArray[78] = new Patch(160, 210, 20, 30);
    patchArray[69] = new Patch(180, 180, 20, 30); patchArray[79] = new Patch(180, 210, 20, 30);
    patchArray[80] = new Patch(0, 240, 20, 30); patchArray[90] = new Patch(0, 270, 20, 30);
    patchArray[81] = new Patch(20, 240, 20, 30); patchArray[91] = new Patch(20, 270, 20, 30);
    patchArray[82] = new Patch(40, 240, 20, 30); patchArray[92] = new Patch(40, 270, 20, 30);
    patchArray[83] = new Patch(60, 240, 20, 30); patchArray[93] = new Patch(60, 270, 20, 30);
    patchArray[84] = new Patch(80, 240, 20, 30); patchArray[94] = new Patch(80, 270, 20, 30);
    patchArray[85] = new Patch(100, 240, 20, 30); patchArray[95] = new Patch(100, 270, 20, 30);
    patchArray[86] = new Patch(120, 240, 20, 30); patchArray[96] = new Patch(120, 270, 20, 30);
    patchArray[87] = new Patch(140, 240, 20, 30); patchArray[97] = new Patch(140, 270, 20, 30);
    patchArray[88] = new Patch(160, 240, 20, 30); patchArray[98] = new Patch(160, 270, 20, 30);
    patchArray[89] = new Patch(180, 240, 20, 30); patchArray[99] = new Patch(180, 270, 20, 30);
    image = new BufferedImage(width, height,BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2D = image.createGraphics();
    public void paint/*Component*/(Graphics g)
    g = (Graphics2D) g2D;
    super.paint/*Component*/(g);
    for (int i = 0; i == 99; i++)
    //for (int s = 0; s > 5; s++)
    // Color[] colours = new Color[6];
    // colours[0] = Color.blue;
    // colours[1] = Color.red;
    // colours[2] = Color.green;
    // colours[3] = Color.orange;
    // colours[4] = Color.black;
    // colours[5] = Color.white;
    // g2D.setColor(colours[s]);
    g2D.setColor(Color.red);
    g2D.fillRect(patchArray.getX(), patchArray[i].getY(),
    patchArray[i].getWidth(), patchArray[i].getHeight());
    g2D.drawImage(image,0, 0, this);

  • Probleme with swing component and keyEvt

    hi ,
    I program this JFrame , when it is empty ( without the Jbutton ) the key Event works fine , but when I add the Jbutton the key event doesn't work anymore.
    I try some focus method but it doesn't seem to work , can you tell me what i can do ...
    Thx.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class test extends JFrame implements KeyListener
        private JButton jb_;
        public test() 
            setSize(320,200);
            this.addKeyListener(this);
            this.getContentPane().setLayout(null);
            jb_ = new JButton("button");
            jb_.setBounds(10,10,100,100);
            this.getContentPane().add(jb_);
        public void keyPressed(KeyEvent e) { System.out.println("OK"); }
        public void keyReleased(KeyEvent e) {}
        public void keyTyped(KeyEvent e) {}
        public static void main(String args[])
         test t = new test();
            t.setDefaultCloseOperation(EXIT_ON_CLOSE);
         t.show();

    i've solved it with creating a JTextArea and putting the button in there
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame implements KeyListener
         private JButton jb_;
         private JTextArea area;
         public Test()
              area = new JTextArea(200,200);
              area.setEditable(false);
              area.addKeyListener(this);
              jb_ = new JButton("button");
              jb_.setBounds(10,10,100,100);
              getContentPane().add(jb_);
              getContentPane().add(area);
              setSize(300,300);
         public void keyPressed(KeyEvent e)
              System.out.println("OK");
         public void keyReleased(KeyEvent e) {}
         public void keyTyped(KeyEvent e) {}
         public static void main(String args[])
              Test t = new Test();
              t.setDefaultCloseOperation(EXIT_ON_CLOSE);
              t.show();
    }

  • Design problem with dynamically added row in datatable

    Hello all,
    I have a dataTable and have developped a method that dynamically adds rows to the dataTable. Each row is made up of two form controls. The problem I have now is that I don't know how to retrieve the values from the mutiple rows. Ideally I would need the values to be stored into a list.
    Can anyone help?
    Thanks in advance,
    Julien.
    Here is my code:
    <h:dataTable var="line" binding="#{TradeClientsAndQuantitiesBean.clientsAndQuantities}"  value="#{TradeClientsAndQuantitiesBean.listOfMiddleFormHelpers}">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="S�lectionnez un client"/>
                    </f:facet>
                    <h:selectOneMenu value="#{TradeClientsAndQuantitiesHelperBean.selectedClientTemp}">
                        <f:selectItems value="#{TradeClientsAndQuantitiesHelperBean.concatenatedLabelMap}"/>
                    </h:selectOneMenu>
                </h:column>   
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Renseignez une quantit�"/>
                    </f:facet>
                    <h:inputText value=""/>
                </h:column>   
            </h:dataTable>

    The values will just be put in the same row object you added to TradeClientsAndQuantitiesBean.listOfMiddleFormHelpers.
    It might be worth to read this article: http://balusc.xs4all.nl/srv/dev-jep-dat.html

  • A small problem with swing

    if the user type no in this code the compiler response an exception error
    see the code
    import java.io.PrintWriter;
    import java.io.FileOutputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import javax.swing.*;
    import java.util.Scanner;
    public class AirlineSystem{
         public static void main(String [] args){
              Scanner in = new Scanner (System.in);
              String name  = "";
              String password ="" ;
              String rePassword ="";
              String cheek ;
              char choiseLetter ;
              char cheekLetter ;
              int type = 0;
              int count = 0 ;
              Scanner inputStream = null ;
              PrintWriter outputStream = null ;
              Security [] passenger = new Security [15000];
              cheek = JOptionPane.showInputDialog ("Are you a new user  ?") ;
              cheek = cheek.trim();
              cheekLetter = cheek.charAt(0) ;
              if (cheekLetter == 'y' || cheekLetter == 'Y'){..}
              for (int i = 0 ; i < passenger.length ; i++){
                        try{
                             inputStream = new Scanner(new FileInputStream("passenger.txt")) ;
                                  catch(IOException e){
                                            JOptionPane.showMessageDialog(null,"an Error happened to the  file: passenger.txt" + e);
                                            System.exit(0) ;
                                  if (inputStream.hasNextLine()){
                                            passenger[ i ].setUserName(inputStream.nextLine()) ;
                                            passenger[ i ].setPassword(inputStream.nextLine()) ;
                                            passenger[ i ].setType( Integer.parseInt(inputStream.nextLine())) ;
                                  else {
                                            passenger [ i ] = null ;
                                            inputStream.close();
                                            break ;
                             name = JOptionPane.showInputDialog ("Please Enter Your name ");
                             for (int i = 0 ; i < passenger.length && passenger [ i ] != null ; i++){
                                  if (passenger [ i ].getUserName() != name ) continue ;
                                  else {
                                       name = passenger [ i ].getUserName() ;
                                       password = passenger [ i ].getPassword() ;
                                       type = passenger [ i ].getType() ;
                                       count ++ ;
                                       break ;
                                  if (count != 0){
                                            for ( int i = 0 ; i < 3 ; i++){
                                                      rePassword = JOptionPane.showInputDialog("please entre your password") ;
                                                      if (password.equals(rePassword) && type == 8600000){
                                                      else if (password.equals(rePassword) && type != 8600000){
                                                      else continue ;
                                  else {
                                                 JOptionPane.showMessageDialog(null,"there is no user called : " + name) ;
                                                 System.exit(0) ;
                                            }Regards

    i faced this" NullPointerException "
    here
    if (passenger [ i ].getUserName() != name ) continue ;
                                  else {
                                  /*from here */      name = passenger [ i ].getUserName() ;
                                       password = passenger [ i ].getPassword() ;
                                       type = passenger [ i ].getType() ;
                                       count ++ ;
                                       break ;
                                  }Edited by: java.student on Jan 12, 2008 9:06 AM

  • Very funny problem, with Swing, please tell me WHY

    Hi, guys ,
    It seems very funny to me when developog a chat application.
    when every time, user enter the text and hit the Enter (through a listener), the text shows up at the screen, and if more texts than the screen, the screen will always focus at the bottom line.
    Hwoever, if you do the same but not via a actionPerformed method,(i.e. a for loop in the main metho) the screen will always focus on the first line of the jTextPane.
    have a try:
    this code will make the focus on the first line, but if you uncomment the thing in the actionPerformed method, and comment one in the main method, if will be totally different
    Please tell me WHY
    import javax.swing.event.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.text.*;
    public class Pane extends JFrame {
    JTextPane txtOutput ;
    StyledDocument document;
    Style normalStyle;
    JTextField jf;
    public Pane()
    Container cont = getContentPane();
    cont.setLayout(new BorderLayout());
    txtOutput = new JTextPane();
    jf = new JTextField(80);
    document = txtOutput.getStyledDocument();
    // Define style for outputStyle
    normalStyle = document.addStyle("Normal", null);
    StyleConstants.setItalic(normalStyle, false);
    StyleConstants.setFontFamily(normalStyle, "Courier");
    StyleConstants.setFontSize(normalStyle, 14);
    StyleConstants.setForeground(normalStyle, Color.red);
    // Now to insert string at end
    txtOutput.setEditable(false);
    cont.add(new JScrollPane(txtOutput),BorderLayout.CENTER);
    cont.add(jf,BorderLayout.SOUTH);
    cont.setVisible(true);
    cont.setBounds(100,300,400,500);
    jf.addActionListener(
    new ActionListener() {
    public void actionPerformed (ActionEvent event)
    //int i = 50;
    //while(i>0){
    //setText1("gegegeg");
    //i--;
    public void setText1(String event) {
    String s= event;
    //s = jf.getText();
    try{
    document.insertString(document.getLength(), s+"\n\n" , normalStyle );
    catch (Exception e) {
    System.out.println("askdf "+e);
    public static void main(String args[])
    Pane p = new Pane();
    p.show();
    System.out.println("I am finish");
    int i = 50;
    while(i>0){
    setText1("gegegeg");
    i--;
    }

    I dunno why, why is it important? if you want it to focus on the last line, just always put a code that makes it focus on the last line, and that's it

  • Web Application Designer Problem with Variable Rolluptime_max

    Hi,
    I needed some help on one of the issues I am facing in the Web template.There is a requirement that a query when executed on the web should have LatestDataUpdate of the data provider on the Header of the Report, which in this case is the Web Template.
    The issue is that I used the Rolluptime_max as the variable to get the value in the Web template and it works fine too in Dev system as I can see the changes on the Web.When I transported the changes to QA system then also it worked fine but in Production after the transport it's not picking up the date.
    I checked the template and the changes which I did is there in Production but it still doesn't pick up the date.
    Can anybody help.I am on BI7.0
    Thanks
    Umang

    I resolved my problem!
    In the Content Administration of the portal:
    -Portal Content
    --Content Provided by SAP
    ---Platform Add-Ons
    Business Intelligence
    iViews
    BEx Web... right click, Open -> Object
    I've deleted the value in the property "BEx Web Application Query String", I put in it nothing.
    Now, it works!
    Bye
    Federico

  • JOGL with SWING problem

    Hello i speak spanish my english is not good
    When i execute a java jogl program i've problem with swing.
    The jogl window catch the events from swing and execute
    accions out control.
    How can i lock the events from swing ?
    Thanks
    [email protected]

    jogl commands: translate, rotate ...
    When a box across the jogl window this commands
    are executed. This box is created with JOptionPane.
    i didnt find a solution yet.

Maybe you are looking for

  • Itunes won't open on a new MacBook

    I just completed my Time Machine installation on a new MacBook Pro from a backup from my old MacBook. Everything is working fine except that when I open Itunes, it keeps quitting unexpectedly and never opens up. Has anyone else had this problem?

  • Where the history of Transaction Codes does get stored?

    Today when I was working on one issue in one SAP system on my PC and later on another system observed that the transaction codes (tcodes) which are there in history were the same for both the systems. Then I started searching for the table or a locat

  • Edit option not enabled for workflow content from within Content Presenter in Webcenter Spaces

    I have a webcenter spaces portal page with a content presenter displaying a html page using the default out of the box template. The html page is located in webcenter content / UCM under a folder on which the " All Reviewer" seeded workflow is enable

  • Vendor Invoice info

    Hi  All, I am looking for FM/tables  that gives some info about Company, Internal Order, Vendor, Invoice Amount, Invoice Date, Tax Amount, Tax Jurisdiction, G/L Account Affected. Could you please help me with this. Thanks in advance, Raja Chandra Ran

  • Erro in SAP VC  with SAP ERP Web Services

    Hello SDN, I wanna use the SAP WebService of an ERP 2005 system in the SAP Visual Composer 7.0 SPS8. I have configured the logical destinations as decibed in http://help.sap.com/saphelp_nw2004s/helpdata/de/f8/7889ce12924273a379c1c590675573/frameset.h