Problem updaing a GridLayout JPanel

Problem updaing a GridLayout JPanel
What I want to do in the following method is very straight forward. First, I will remove all components inside the namesPanel, then reset the layout and add new things back to the panel. However, now it does not clean up things. For example, if I set numberOfPlayers to 10, and call this method, 10 users info will be shown. Then if I set numberOfPlayers to 2, more than 2 users' info will be shown! Some info from the previous 10 users will be left behind. Is there a better way to clean up things?
Also, if I call this method right after I add the namesPanel to its parent panel, which will be added to the contentPanel of JFrame, it won't work, but it will work if I call it after that through the actionPerformed method. The value of numberOfPlayers is set by a JComboBox. When a user selects an item, numberOfPlayers will be changed, and the populateNames() will be called through the actionPerformed method. Thank you in advance.
public void populateNames(){
         namesPanel.removeAll();
         jf.pack();
         namesPanel.setLayout(new GridLayout(numberOfPlayers+1, 2));
         JTextField[] jt_playerNames = new JTextField[numberOfPlayers];
         playerNames = new String[numberOfPlayers];
        for(int i=0;i<numberOfPlayers;i++){
             namesPanel.add(new JLabel("Player name:"));
            jt_playerNames[i] = new JTextField("Player " + (i+1));
            playerNames[i] = "Player " + (i+1);
            namesPanel.add(jt_playerNames);

No, namesPanel.revalidate(); doesn't help. jf.repaint() actually works.
But it still doesn't work the first time I call it right before I add it to its parent panel.

Similar Messages

  • Advance level drawing problem with Jframe and JPanel need optimize sol?

    Dear Experts,
    I m trying to create a GUI for puzzle game following some kind of "game GUI template", but i have problems in that,so i tried to implement that in various ways after looking on internet and discussions about drawing gui in swing, but i have problem with both of these, may be i m doing some silly mistake, which is still out of my consideration. please have a look at these two and recommend me one of them, which is running without problems (flickring and when you enlarge window the board draw copies (tiled) everywhere,
    Note: i don't want to inherit jpanel or Jframe
    here is my code : import java.awt.BorderLayout;
    public class GameMain extends JFrame {
         private static final long serialVersionUID = 1L;
         public int mX, mY;
         int localpoints = 0;
         protected static JTextField[][] squares;
         protected JLabel statusLabel = new JLabel("jugno");
         Label lbl_score = new Label("score");
         Label lbl_scorelocal = new Label("local score");
         protected static TTTService remoteTTTBoard;
         // Define constants for the game
         static final int CANVAS_WIDTH = 800; // width and height of the game screen
         static final int CANVAS_HEIGHT = 600;
         static final int UPDATE_RATE = 4; // number of game update per second
         static State state; // current state of the game
         private int mState;
         // Handle for the custom drawing panel
         private GameCanvas canvas;
         // Constructor to initialize the UI components and game objects
         public GameMain() {
              // Initialize the game objects
              gameInit();
              // UI components
              canvas = new GameCanvas();
              canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
              this.setContentPane(canvas);
              this.setDefaultCloseOperation(EXIT_ON_CLOSE);
              this.pack();
              this.setTitle("MY GAME");
              this.setVisible(true);
         public void gameInit() {     
         // Shutdown the game, clean up code that runs only once.
         public void gameShutdown() {
         // To start and re-start the game.
         public void gameStart() {
         private void gameLoop() {
         public void keyPressed(KeyEvent e) {
         public void keyTyped(KeyEvent e) {
         public void gameKeyReleased(KeyEvent e) {
              PuzzleBoard bd = getBoard();
              for (int row = 0; row < 4; ++row) {
                   for (int col = 0; col < 4; ++col) {
                        if (e.getSource() == squares[row][col]) {
                             if (bd.isOpen(col, row)) {
                                  lbl_score.setText("Highest Score = "
                                            + Integer.toString(bd.getPoints()));
                                  setStatus1(bd);
                                  pickSquare1(col, row, squares[row][col].getText()
                                            .charAt(0));
         protected void pickSquare1(int col, int row, char c) {
              try {
                   remoteTTTBoard.pick(col, row, c);
              } catch (RemoteException e) {
                   System.out.println("Exception: " + e.getMessage());
                   e.printStackTrace();
                   System.exit(1);
         // method "called" by remote object to update the state of the game
         public void updateBoard(PuzzleBoard new_board) throws RemoteException {
              String s1;
              for (int row = 0; row < 4; ++row) {
                   for (int col = 0; col < 4; ++col) {
                        squares[row][col].setText(new_board.ownerStr(col, row));
              lbl_score.setText("Highest Score = "
                        + Integer.toString(new_board.getPoints()));
              setStatus1(new_board);
         protected void setStatus1(PuzzleBoard bd) {
              boolean locals = bd.getHave_winner();
              System.out.println("local win" + locals);
              if (locals == true) {
                   localpoints++;
                   System.out.println("in condition " + locals);
                   lbl_scorelocal.setText("Your Score = " + localpoints);
              lbl_score
                        .setText("Highest Score = " + Integer.toString(bd.getPoints()));
         protected PuzzleBoard getBoard() {
              PuzzleBoard res = null;
              try {
                   res = remoteTTTBoard.getState();
              } catch (RemoteException e) {
                   System.out.println("Exception: " + e.getMessage());
                   e.printStackTrace();
                   System.exit(1);
              return res;
         /** Custom drawing panel (designed as an inner class). */
         class GameCanvas extends JPanel implements KeyListener {
              /** Custom drawing codes */
              @Override
              public void paintComponent(Graphics g) {
                   // setOpaque(false);
                   super.paintComponent(g);
                   // main box; everything placed in this
                   // JPanel box = new JPanel();
                   setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                   // add(statusLabel, BorderLayout.NORTH);
                   // set up the x's and o's
                   JPanel xs_and_os = new JPanel();
                   xs_and_os.setLayout(new GridLayout(5, 5, 0, 0));
                   squares = new JTextField[5][5];
                   for (int row = 0; row < 5; ++row) {
                        for (int col = 0; col < 5; ++col) {
                             squares[row][col] = new JTextField(1);
                             squares[row][col].addKeyListener(this);
                             if ((row == 0 && col == 1) || (row == 2 && col == 3)
                             || (row == 1 && col == 4) || (row == 4 && col == 4)
                                       || (row == 4 && col == 0))
                                  JPanel p = new JPanel(new BorderLayout());
                                  JLabel label;
                                  if (row == 0 && col == 1) {
                                       label = new JLabel("1");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else if (row == 4 && col == 0) {// for two numbers or
                                       // two
                                       // blank box in on row
                                       label = new JLabel("2");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else if (row == 1 && col == 4) {
                                       label = new JLabel("3");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else if (row == 4) {
                                       label = new JLabel("4");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  else {
                                       label = new JLabel("5");
                                       label.setHorizontalAlignment(JLabel.LEFT);
                                       label.setVerticalAlignment(JLabel.TOP);
                                  label.setOpaque(true);
                                  label.setBackground(squares[row][col].getBackground());
                                  label.setPreferredSize(new Dimension(label
                                            .getPreferredSize().width, squares[row][col]
                                            .getPreferredSize().height));
                                  p.setBorder(squares[row][col].getBorder());
                                  squares[row][col].setBorder(null);
                                  p.add(label, BorderLayout.WEST);
                                  p.add(squares[row][col], BorderLayout.CENTER);
                                  xs_and_os.add(p);
                             } else if ((row == 2 && col == 1) || (row == 1 && col == 2)
                                       || (row == 3 && col == 3) || (row == 0 && col == 3)) {
                                  xs_and_os.add(squares[row][col]);
                                  // board[ row ][ col ].setEditable(false);
                                  // board[ row ][ col ].setText("");
                                  squares[row][col].setBackground(Color.RED);
                                  squares[row][col].addKeyListener(this);
                             } else {
                                  squares[row][col] = new JTextField(1);
                                  // squares[row][col].addActionListener(this);
                                  squares[row][col].addKeyListener(this);
                                  xs_and_os.add(squares[row][col]);
                   this.add(xs_and_os);
                   this.add(statusLabel);
                   this.add(lbl_score);
                   this.add(lbl_scorelocal);
              public void keyPressed(KeyEvent e) {
              public void keyReleased(KeyEvent e) {
                   gameKeyReleased(e);
              public void keyTyped(KeyEvent e) {
         // main
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   @Override
                   public void run() {
                        new GameMain();
      thanks a lot for your time , consideration and efforts.
    jibby
    Edited by: jibbylala on Sep 20, 2010 6:06 PM

    jibbylala wrote:
    thanks for mentioning as i wasn't able to write complete context here.Yep thanks camickr. I think that Darryl's succinct reply applies here as well.

  • Problem with JFrame and JPanel

    Okay, well I'm busy doing a lodge management program for a project and I have programmed this JFrame
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FinalTest extends JFrame
         public JPanel contentPane;
         public JImagePanel imgPanel;
         private JLabel[] cottageIcon;
         private boolean keepMoving;
         private int selectedCottage;
         public FinalTest()
              super();
              initializeComponent();
              addActionListeners();
              this.setVisible(true);
         private void initializeComponent()
              contentPane = (JPanel)getContentPane();
              contentPane.setLayout(null);
              imgPanel = new JImagePanel("back.png");
               imgPanel.setLayout(null);
              imgPanel.setBackground(new Color(1, 0, 0));
                   addComponent(contentPane, imgPanel, 10,10,imgPanel.getImageWidth(),imgPanel.getImageHeight());
              cottageIcon = new JLabel[6];
              keepMoving = true;
              selectedCottage = 0;
              cottageIcon[0] =  new JLabel();
              //This component will never be added or shown, but needs to be there to cover for no cottage selected
              for(int a = 1; a < cottageIcon.length; a++)
                   cottageIcon[a] = new JLabel("C" + (a));
                   cottageIcon[a].setBackground(new Color(255, 0, 0));
                    cottageIcon[a].setHorizontalAlignment(SwingConstants.CENTER);
                    cottageIcon[a].setHorizontalTextPosition(SwingConstants.LEADING);
                    cottageIcon[a].setForeground(new Color(255, 255, 255));
                    cottageIcon[a].setOpaque(true);
                    addComponent(imgPanel,cottageIcon[a],12,(a-1)*35 + 12,30,30);
                this.setTitle("Cottage Chooser");
                this.setLocationRelativeTo(null);
              this.setSize(new Dimension(540, 430));
         private void addActionListeners()
              imgPanel.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        imgPanel_mousePressed(e);
                   public void mouseReleased(MouseEvent e)
                        imgPanel_mouseReleased(e);
                   public void mouseEntered(MouseEvent e)
                        imgPanel_mouseEntered(e);
              imgPanel.addMouseMotionListener(new MouseMotionAdapter()
                   public void mouseDragged(MouseEvent e)
                        imgPanel_mouseDragged(e);
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         private void imgPanel_mousePressed(MouseEvent e)
              for(int a = 1; a < cottageIcon.length; a++)
                   if(withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()))
                        System.out.println("B" + withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()));
                        selectedCottage = a;
                        keepMoving = true;
         private void imgPanel_mouseReleased(MouseEvent e)
              System.out.println("called");
              selectedCottage = 0;
              keepMoving = false;
         private void imgPanel_mouseDragged(MouseEvent e)
               System.out.println("XXX" + Math.random() * 100);
              if(keepMoving)
                   int x = e.getX();
                    int y = e.getY();
                    if(selectedCottage!= 0)
                         cottageIcon[selectedCottage].setBounds(x-(30/2),y-(30/2),30,30);
                    if(!legalBounds(imgPanel,cottageIcon[selectedCottage]))
                        keepMoving = false;
                        cottageIcon[selectedCottage].setBounds(imgPanel.getWidth()/2,imgPanel.getHeight()/2,30,30);
              System.out.println(cottageIcon[selectedCottage].getBounds());
         private void imgPanel_mouseEntered(MouseEvent e)
               System.out.println("entered");
         private void but1_actionPerformed(ActionEvent e)
              String input = JOptionPane.showInputDialog(null,"Enter selected cottage");
              selectedCottage = Integer.parseInt(input) - 1;
         public boolean legalBounds(Component containerComponent, Component subComponent)
              int contWidth = containerComponent.getWidth();
              int contHeight = containerComponent.getHeight();
              int subComponentX = subComponent.getX();
              int subComponentY = subComponent.getY();
              int subComponentWidth = subComponent.getWidth();
              int subComponentHeight = subComponent.getHeight();
              if((subComponentX < 0) || (subComponentY < 0) || (subComponentX > contWidth) || (subComponentY > contHeight))
                   return false;
              return true;
         public boolean withinBounds(int mouseX, int mouseY, Rectangle componentRectangle)
              int componentX = (int)componentRectangle.getX();
              int componentY = (int)componentRectangle.getY();
              int componentHeight = (int)componentRectangle.getHeight();
              int componentWidth = (int)componentRectangle.getWidth();
              if((mouseX >= componentX) && (mouseX <= (componentX + componentWidth)) && (mouseY >= componentY) && (mouseY <= (componentY + componentWidth)))
                   return true;
              return false;
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              //JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
              FinalTest ft = new FinalTest();
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class JImagePanel extends JPanel
      private Image image;
      public JImagePanel(String imgFileName)
           image = new ImageIcon(imgFileName).getImage();
        setLayout(null);
      public void paintComponent(Graphics g)
        g.drawImage(image, 0, 0, null);
      public Dimension getImageSize()
                Dimension size = new Dimension(image.getWidth(null), image.getHeight(null));
             return size;
      public int getImageWidth()
                int width = image.getWidth(null);
                return width;
      public int getImageHeight()
              int height = image.getHeight(null);
              return height;
    }Now the problem I'm having is changing that class to a JFrame, it seems simple but I keep having problems like when it runs from another JFrame nothing pops up. I can do it like this:
    FinalTest ft = new FinalTest();
    ft.setVisible(false);
    JPanel example = ft.contentPanehowever I will probably be marked down on this for bad code. I'm not asking for the work to be done for me, but I'm really stuck on this and just need some pointers so I can carry on with the project. Thanks,
    Steve

    CeciNEstPasUnProgrammeur wrote:
    I'd actually consider your GUI being a JPanel instead of a JFrame quite good design - makes it easy to put the stuff into an applet when necessary...
    Anyway, you should set setVisible() to true to make it appear, not to false. Otherwise, I don't seem to understand your problem.That is actually my problem. I am trying to convert this JFrame to a JPanel

  • Problem with Graphics and JPanel...

    I would like to draw a rectangle on a JPanel. Here is my code:
    JPanel panel = new JPanel();
    Graphics g = panel.getGraphics();
    g.drawRect(20,20,20,20);
    When I run my program, I have a NullPointerException...
    Do you any suggestions to fix the problem??
    thanks
    Pete

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    public class pete extends JFrame {
      public pete() {
        JPanel panel = new JPanel() {
          public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int midx = getSize().width / 2;
            int midy = getSize().height / 2;
            g2.draw(new Rectangle2D.Double(midx/2, midy/2, midx, midy));
        getContentPane().add(panel, "Center");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400,300);
        setLocation(300,100);
        setVisible(true);
      public static void main(String[] args) {
        new pete();
    }

  • Problem with JTable and JPanel

    Hi,
    I'm having problems with a JTable in a JPanel. The code is basicly as follows:
    public class mainFrame extends JFrame
            public mainFrame()
                    //A menu is implemeted giving rise to the following actions:
                    public void actionPerformed(ActionEvent evt)
                            String arg = evt.getActionCommand();
                            if(arg.equals("Sit1"))
                            //cells, columnNames are initiated correctly
                            JTable table = new JTable(cells,columnNames);
                            JPanel holdingPanel = new JPanel();
                            holdingPanel.setLayout( new BorderLayout() );
                            JScrollPane scrollPane = new JScrollPane(holdingPanel);
                            holdingPanel.setBackground(Color.white);
                            holdingPanel.add(table,BorderLayout.CENTER);
                            add(scrollPane, "Center");
                            if(arg.equals("Sit2"))
                                    if(scrollPane !=null)
                                            remove(scrollPane);validate();System.out.println("ScrollPane");
                                    if(holdingPanel !=null)
                                            remove(holdingPanel);
                                    if(table !=null)
                                            remove(table);table.setVisible(false);System.out.println("table");
                            //Put other things on the holdingPanel....
            private JScrollPane scrollPane;
            private JPanel holdingPanel;
            private JTable table;
    }The problem is that the table isn't removed. When you choose another situation ( say Sit2), at first the table apparently is gone, but when you press with the mouse in the area it appeared earlier, it appears again. How do I succesfully remove the table from the panel? Removing the panel doesn't seem to be enough. Help is much appreciated...
    Best regards
    Schwartz

    If you reuse the panel and scroll pane throughout the application,
    instantiate them in the constructor, not in an often-called event
    handler. In the event handler, you only do add/remove of the table
    on to the panel. You can't remove the table from the container
    which does not directly contain it.
    if (arg.equals("Sit2")){
      holdingPanel.remove(table);
      holdingPanel.revalidate();
      holdingPanel.repaint(); //sometimes necessary
    }

  • Problem with repaint() in JPanel

    Hi,
    This is the problem: I cyclically call the repaint()-method but there is no effect of it.
    When does it appear: The problem occurs by calling the repaint()-method of a JPanel -class.
    This is what i am doing: The repaint() is called from a different class which is my GUI. I do this call in an endless loop which is done within a Thread.
    I tried to add a KeyListener to the JPanel-class and there I called the repaint()-method when i press a Key. Then the Panel is repainted.
    so I implemented a "callRepaint"-method in the JPanel-class that does nothing else than call repaint() (just like the keyPressed()-method does). But when i cyclically call this "callRepaint"-method from my GUI nothing happens.
    Now a few codedetails:
    // JPanel-class contains:
    int i = 0;
    public void callRepaint(){
                    repaint();
    public void paintComponent(Graphics g){
            super.paintComponent(g);
            g.drawLine(i++,0,200,200);
    public void keyPressed(KeyEvent e) {
            repaint();                       // This is working
    //GUI-class contains:
    // This method is called cyclically
    public void draw() {
                  lnkJPanelclass.repaint();             // This calling didn't work
                  // lnkJPanelclass.callRepaint();  // This calling didn't work     
    Thanks for your advices in advance!
    Cheers spike

    @ARafique:
    This works fine:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Date;
    import javax.swing.*;
    public class Test extends JFrame implements ActionListener{
        private JTextField label;
        private Timer timer;
        private Container cont;
        public Test() {
            label = new JTextField("",0);
            timer = new Timer(1000,this);
            cont = getContentPane();
            cont.add(label);
            setSize(250,70);
            setDefaultCloseOperation(3);
            setVisible(true);
            timer.start();
        public void actionPerformed(ActionEvent e){
            label.setText(new Date(System.currentTimeMillis()).toString());
        public static void main(String[] args){
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new Test();
    }no repaint()/revalidate() needed

  • Problem to print a JPanel containing jfreeChart

    I need help
    I am developping an application that should display and print reports with histograms.
    I make the histogram with Jfreechart and put it on a JPanel. the report is a Vector of JPanel.
    1. When i print only the panel containing the JFreechart, the panel is printed but the range axis label
    of JFreechart is inverted.
    2. When i print all the report, nothing appears on the page of the panel containing JFreechart.
    here is my printing code:
    //code
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
    if (pageIndex >= docToBePrinted.size()) {
    return (NO_SUCH_PAGE);
    } else {
    componentToBePrinted = docToBePrinted.get(pageIndex);
    //componentToBePrinted.repaint();
    Dimension dim = componentToBePrinted.getSize();
    double scaleX = pageFormat.getImageableWidth() / dim.width;
    double scaleY = pageFormat.getImageableHeight() / dim.height;
    double scale = Math.min(scaleX, scaleY);
    Graphics2D g2D = (Graphics2D) g;
    // g2D.translate(0, 0);
    g2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    g2D.scale(scale, scale);
    g2D.setPaintMode();
    disableDoubleBuffering(componentToBePrinted);
    componentToBePrinted.print(g2D);
    g2D.dispose();
    //componentToBePrinted.printAll(g2D);
    enableDoubleBuffering(componentToBePrinted);
    //componentToBePrinted.
    return (PAGE_EXISTS);
    //end of code
    "docToBePrinted" is the report
    Could anyone help me please !

    I have the same problem. Similarly to another entry here, be very careful about how many times you reattempt it. I did it several times, hoping it would work out a kink, and it was on an expensive order, now there are over $2000 of "temporary authorizations" depleting my available credit on my card, and it's been that way for almost a week now.
    I am living overseas, and am unfortunately restricted to dial-up internet to upload this, and it either gets stuck at 64kb/8Mb or just jumps right to 8/8Mb, when there is nothing wrong with the my internet connection.
    I emailed Apple in response to the order cancellation email, and stated that perhaps it was the army firewall I'm behind, asking for the site the program connects to in an attempt to unblock the site if it's inadvertently getting blocked on my end. When they replied they said it's a technical issue and that I can call Apple to talk with someone, where they will determine how much the call will cost. That's outrageous to have something brand new, and have to pay for them to help you on an issue that truly may be as simple as giving out a website.
    In response to an earlier reply, I am using iPhoto 5.0.4, and I just purchased my G5 back in October. Is there a later version to iLife that I'm not finding?
    If anyone finds help with this issue, I would greatly appreciate some tips!
    Thanks so much,
    Dave

  • Problem displaying image in jpanel

    Hi,I have posted this on the applet board, but I think its also a general programming problem, so apologies if it isn't relevant to this board, just say so and I'll remove it!
    I've got an applet that receives a variable from a PHP page as a parameter. The variable is "map1.png" the map this variable refers to sits in the same folder as the applet.
    I want to use this variable along with getDocumentBase() to create a URL which will then be used to display an image within a jPanel called mapPane.
    the code I currently have is:
    // get image url
    String mapURL = getParameter("mapURL");
    //set variable for image
    Image map_png;
    // set media tracker
    MediaTracker mt;
    //initialise media tracker     
    mt = new MediaTracker(this);
    map_png = getImage(getDocumentBase(),mapURL);
    // tell the MediaTracker to kep an eye on this image, and give it ID 1;
    mt.addImage(map_png,1);
    // now tell the mediaTracker to stop the applet execution
    // until the images are fully loaded.
    try
    mt.waitForAll();
    catch (InterruptedException e) {}
    // draw image onto mapPane
    mapPane.getGraphics().drawImage(map_png, 200, 200, null);
    Currently the Parameter is being passed into the applet (i've written it out within the applet) but the image is not being displayed. Does anyone have any suggestions about what I'm doing wrong?
    Cheers
    Steve

    hi,
    No, don't get any exceptions, the Java Console has a message:
    <terminated>JavaImageEditor[Java Applet]C:\Program Files\Java\jre1.6.0\bin\javaw.exe
    Cheers
    Steve

  • Problems with basic Java JPanel animation using paintcomponent

    okay so I am trying to animate a sprite moving across a background using a for loop within the paintComponent method of a JPanel extension
    public void paintComponent(Graphics g){
    Image simpleBG = new ImageIcon("Images/Backgrounds/Simple path.jpg").getImage();
    Image mMan = new ImageIcon("Images/Sprites/hMan.gif").getImage();
    if (!backgroundIsDrawn){
    g.drawImage(simpleBG, 0, 0, this);
    g.drawImage(mMan, xi, y, this);
    backgroundIsDrawn=true;
    else
    for (int i=xi; i<500; i++){
    g.drawImage(simpleBG, 0, 0, this);
    g.drawImage(mMan, i, y, this);
    try{
    Thread.sleep(10);
    } catch(Exception ex){System.out.println("damn");}
    The problem is that no matter what I set my thread to, it will not show the animation, it will just jump to the last location, even if the thread sleep is set high enough that it takes several minutes to calculate,, it still does not paint the intemediary steps.
    any solution, including using a different method of animation all together would be greatly appreciated. I am learning java on my own so i need all the help I can get.

    fysicsandpholds1014 wrote:
    even when I placed the thread sleep outside of the actual paintComponent in a for loop that called repaint(), it still did not work? Nope. Doing this will likely put the Event Dispatch Thread or EDT to sleep. Since this is the main thread that is responsible for Swing's painting and user interaction, you'll put your app to sleep with this. Again, use a Swing Timer
    and is there any easy animation method that doesnt require painting and repainting every time becasue it is very hard to change what I want to animate with a single paintComponent method? I don't get this.
    I find the internet tutorials either way too complicated or not nearly in depth enough. Maybe its just that I am new to programming but there doesn't seem to be a happy medium between dumbed down Swing tutorials and very complicated and sophisticated animation algorithmns.I can only advise that you practice, practice, practice. The more you use the tutorials, the easier they'll be to use.
    Here's another small demo or animation. It is not optimized (repaint is called on the whole JPanel), but demonstrates some points:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    @SuppressWarnings("serial")
    public class AnimationDemo2 extends JPanel {
      // use a publicly available sprite for this example
      private static final String SPRITE_PATH = "http://upload.wikimedia.org/" +
                "wikipedia/commons/2/2e/FreeCol_flyingDutchman.png";
      private static final int SIDE = 600;
      private static final Dimension APP_SIZE = new Dimension(SIDE, SIDE);
      // timer delay: equivalent to the Thread.sleep time
      private static final int TIMER_DELAY = 20;
      // how far to move in x dimension with each loop of timer
      public static final int DELTA_X = 1;
      // holds our sprite image
      private BufferedImage img = null;
      // the images x & y locations
      private int imageX = 0;
      private int imageY = SIDE/2;
      public AnimationDemo2() {
        setPreferredSize(APP_SIZE);
        try {
          // first get our image
          URL url = new URL(SPRITE_PATH);
          img = ImageIO.read(url);
          imageY -= 3*img.getHeight()/4;
        } catch (Exception e) { // shame on me for combining exceptions :(
          e.printStackTrace();
          System.exit(1); // exit if fails
        // create and start the Swing Timer
        new Timer(TIMER_DELAY, new TimerListener()).start();
      // all paintComponent does is paint -- nothing else
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.blue);
        int w = getWidth();
        int h = getHeight();
        g.fillRect(0, h/2, w, h);
        if (img != null) {
          g.drawImage(img, imageX, imageY, this);
      private class TimerListener implements ActionListener {
        // is called every TIMER_DELAY ms
        public void actionPerformed(ActionEvent e) {
          imageX += DELTA_X;
          if (imageX > getWidth()) {
            imageX = 0;
          // ask JVM to paint this JPanel
          AnimationDemo2.this.repaint();
      // code to place our JPanel into a JFrame and show it
      private static void createAndShowUI() {
        JFrame frame = new JFrame("Animation Demo");
        frame.getContentPane().add(new AnimationDemo2());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      // call Swing code in a thread-safe manner
      public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
            createAndShowUI();
    }

  • Problem with multiple transparent JPanels

    Hi,
    I'm currently trying to implement some kind of message box that can fade in and out. This message box is a subclass of JComponent, the message it contains can be an arbitrary Swing-Component.
    The message container and the message itself have the same background color. When fading, the (partly transparent) colors of the of the container and the message are added, which I do not want.
    Here are two images to illustrate my problem:
    What I have: http://www.inf.tu-dresden.de/~ab023578/javaforum/reality.gif
    What I want: http://www.inf.tu-dresden.de/~ab023578/javaforum/wish.gif
    Here is the code:
    import java.awt.*;
    import javax.swing.*;
    public class Main {
        static float transparency = 0f;
        public static void main(String[] args) {
            JPanel jpBack = new JPanel() {
                protected void paintComponent(Graphics g) {
                    Graphics2D g2d = (Graphics2D)g;
                    g2d.clearRect(0, 0, getWidth(), getHeight());
                    g2d.setColor(getBackground());
                    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency);
                    g2d.setComposite(alpha);
                    g2d.fillRect(0, 0, getWidth(), getHeight());
            jpBack.setBackground(Color.WHITE);
            jpBack.setLayout(null);
            JPanel jpContainer = new JPanel();
            jpContainer.setBackground(Color.RED);
            jpContainer.setLayout(null);
            JPanel jpMessage = new JPanel();
            jpMessage.setBackground(Color.RED);
            JLabel jlMessage = new JLabel("MESSAGE");
            jpBack.add(jpContainer);
            jpContainer.add(jpMessage);
            jpMessage.add(jlMessage);
            jpContainer.setBounds(10, 10, 120, 100);
            jpMessage.setBounds(10, 10, 100, 50);
            JFrame frame = new JFrame();
            frame.setBounds(0, 0, 150, 150);
            frame.setBackground(Color.WHITE);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(jpBack);
            frame.setVisible(true);
            for (double a = 0; true; a += 0.01D) {
                try {
                    Thread.sleep(10);
                catch (InterruptedException e) {}
                transparency = (float)Math.abs(Math.sin(a));
                jpBack.repaint();
    }I understand that the Porter-Duff-Rule SRC_OVER causes the container to be drawn over the message (or vice versa) and both of them over the background. I think what I need is a way to handle the whole jpContainer-Panel and all its subcomponents as a single source image. Is that possible?

    Thank you for your answer, Sarcommand. Unfortunately the test program I provided is a bit too simple as your solution works here but not for my original problem. :|
    Let me explain what I want to achieve and why.
    I'm writing a tool for algorithm visualisation. Currently I am dealing with a parsing algorithm (having compontents such as an automaton with an input tape, output tape and a stack). Those components (containers) can contain multiple JComponents (GraphicalObjects), which display a BufferedImage that can be altered during the animation.
    I want to create my message windows the same way. A container that contains GraphicalObjects (or, if necessary, any other Swing component). One GraphicalObject has a very limited field of responsibility: mereley displaying its information.
    Aligning the GraphicalObject is one of the container's responsibilities.
    What I'm currently trying to do is to put my GraphicalMessage into the center of a container, leaving an offset on the left/right/upper/lower side. This is why I need the same background color for both the GraphicalMessage and the MessageContainer, I don't want the user to see that there are actually two JComponents on top of each other.
    While I could use another approach for text messages I prefer this one as I would be able to fade arbitrary Containers and their GraphicalObjects .
    Here is the code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.image.BufferedImage;
    public class Main {
        static float transparency = 0f;
        public static void main(String[] args) {
            JPanel jpBack = new JPanel() {
                protected void paintComponent(Graphics g) {
                    Graphics2D g2d = (Graphics2D)g;
                    g2d.clearRect(0, 0, getWidth(), getHeight());
                    g2d.setColor(getBackground());
                    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparency);
                    g2d.setComposite(alpha);
                    g2d.fillRect(0, 0, getWidth(), getHeight());
                    super.paintComponent(g);
            jpBack.setBackground(Color.WHITE);
            jpBack.setLayout(null);
            JPanel jpContainer = new JPanel();
            jpContainer.setBackground(Color.RED);
            jpContainer.setLayout(null);
            GraphicalMessage msg = new GraphicalMessage();
            jpBack.add(jpContainer);
            jpContainer.add(msg);
            jpContainer.setBounds(10, 10, 120, 100);
            msg.setBounds(10, 10, 160, 60);
            JFrame frame = new JFrame();
            frame.setBounds(0, 0, 150, 150);
            frame.setBackground(Color.WHITE);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(jpBack);
            frame.setVisible(true);
            float stepSize = 0.01f;
            float step = stepSize;
            for (float a = 0; true; a += step) {
                try {
                    Thread.sleep(10);
                catch (InterruptedException e) {}
                if (a >= 1) {
                    step = -stepSize;
                    a -= stepSize;
                if (a <= 0) {
                    step = stepSize;
                    a += stepSize;
                    msg.updateInternalContent();
                    msg.redraw();
                transparency = a;
                jpBack.repaint();
    class GraphicalMessage extends JComponent {
        private String text;
        private Graphics2D ig2d;
        private BufferedImage image;
        public GraphicalMessage() {
            setLayout(null);
            image = new BufferedImage(100, 50, BufferedImage.TYPE_INT_ARGB);
            ig2d = image.createGraphics();
            ig2d.setColor(Color.BLACK);
            ig2d.setBackground(Color.RED);
            ig2d.setFont(new Font("Courier New", Font.BOLD, 20));
            updateInternalContent();
            redraw();
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D)g;
            g2d.drawImage(image, 0, 0, null);
        public void redraw() {
            ig2d.clearRect(0, 0, image.getWidth(), image.getHeight());
            ig2d.drawString(text, 0, 20);
        public void updateInternalContent() {
            text = String.valueOf((int)(Math.random() * 10000));
    }A possibility to erase the text from the BufferedImage without having to draw a rectangle would help me as well.

  • Problems displaying image in JPanel

    Hi, I've got an applet that receives a variable from a PHP page as a parameter. The variable is "map1.png" the map this variable refers to sits in the same folder as the applet.
    I want to use this variable along with getDocumentBase() to create a URL which will then be used to display an image within a jPanel called mapPane.
    the code I currently have is:
    // get image url
            String mapURL = getParameter("mapURL");
            //set variable for image
            Image map_png;
            // set media tracker
            MediaTracker mt;
            //initialise media tracker             
            mt = new MediaTracker(this);
            map_png = getImage(getDocumentBase(),mapURL);
            // tell the MediaTracker to kep an eye on this image, and give it ID 1;
            mt.addImage(map_png,1);
            // now tell the mediaTracker to stop the applet execution
            //  until the images are fully loaded.
            try
                 mt.waitForAll();
            catch (InterruptedException  e) {}
            // draw image onto mapPane
            mapPane.getGraphics().drawImage(map_png, 200, 200, null);Currently the Parameter is being passed into the applet (i've written it out within the applet) but the image is not being displayed. Does anyone have any suggestions about what I'm doing wrong?
    Cheers
    Steve

    Hello,
    after an update of the graphics card driver to the newest just released version the problem has vanished.
    Regards

  • Mouse clicks in a GridLayout JPanel

    Hi. I have a JPanel set as a GridLayout (3 columns, infinite rows) I am populating this panel with thumbnail images and need to be able to identify when a user clicks on a thumbnail image and respons accordingly. The thumbnail images are not the same size as the grid squares. How can i alter the mouseclicked event to act in this way?

    Put the Images in a Collection and assign anonymous Listeners to them:
    GridLayout gl = new GridLayout(3);
    JPanel jp = new JPanel();
    jp.setLayout(gl);
    String[] imageNames = new String[50];
    Image[] images = new Image[imageNames.length];
    ImageIcon buttonIcons = new ImageIcon[imageNames.length];
    JButton buttons = new JButton[imageNames.length];
    for ( int i = 0; i < imageNames.length; i++ ) {
      URL url = getClass().getResource( imageName[i] );
      images[i] = Toolkit.getDefaultToolkit().getImage( url );
      buttonIcons[i] = new ImageIcon( images[i] );
      buttons[i] = new JButton(buttonIcons);
    buttons[i].setBorderPainted(false);
    b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    System.out.println("You clicked on "+imageName[i]);
    jp.add(buttons[i]);

  • Problem with gridbaglayout in JPanel

    Hello I am trying to display contact information in three serperate Jpanels on tabbbed panes.I would like to get help in configuring maybe just the pane of void showPane1().I need something like
    Searchlb | Combodropname1
    firstnamelb | firstnametxt | lastnamelb | lastnametxt
    Addresslb addresslb.Horizontal-----------------------*-
    citylb | citytxt | statelb | statetxt
    postcodelb | postcodetxt | countrylb | countrytxt
    emaillb | emailtxt | homephonelb | homephonetxt
    faxnumberlb | faxnumbertxt
    Other panes have buttons
    Here`s the code it operates on login of MSAccess table called persons:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.io.*;
    import java.util.Date;
    import java.text.NumberFormat;
    public class Addressbook extends JFrame{
         // Define constant variables
         final static String driver      = "sun.jdbc.odbc.JdbcOdbcDriver";
         final static String url      = "jdbc:odbc:addBKTAFE";
         final static String login      = "LOG-IN";
         final static String tab_login      = "Log-in";
         final static String tab1      = "INQUIRE Personnel Details";
         final static String tab2      = "UPDATE/DELETE Personnel Details";
         final static String tab3      = "INSERT Personnel Details";
         final static String insert      = "SAVE RECORD";
         final static String update           = "UPDATE RECORD";
         final static String delete      = "DELETE RECORD";
         final static String inquire      = "INQUIRE RECORD";
         final static String clear      = " CLEAR ";
         final static String relogin      = "Log-in failed! Please relog-in!";
         final static String norecfound      = "No Record Found!";
         final static String recinserted     = "Record Inserted!";
         final static String recupdated      = "Record Updated!";
         final static String recdeleted      = "Record Deleted!";
         final static String numericerror = "Age should be numeric!";
         final static String information = "INFORMATION";
         final static String error      = "ERROR";
         final static String genexception = "GENERAL EXCEPTION";
         final static String sqlexception = "SQL EXCEPTION";
         final static String confdelete = "CONFIRM DELETE";
         final static String slash      = "/";
         final static String table1      = "persons";
         final static String table2      = "Addresses";
    // Events events = new Events(this);
         // Define variables     for general use
         String sql = ""; // Used to store sql statements
         int pane_number = 0; // Used to indicate what screen needs to be processed
                                       // like resetting input fields and comboboxes
         boolean abort = false;// Used to indicate if error found to avoid further
                                       // processing/validations
         // Define container, panels and tabbedpane
    Container cntr = getContentPane();
    JTabbedPane tpane = new JTabbedPane();
         JPanel      cbpanel1 , cbpanel2 , cbpanel3,
                   panel1 , panel2 , panel3;
         // Setup constraints and type of layout
         GridBagConstraints constraints = new GridBagConstraints();
         GridBagConstraints constraints1 = new GridBagConstraints();
         GridBagConstraints constraints2 = new GridBagConstraints();
         GridBagConstraints constraints3 = new GridBagConstraints();
         GridBagLayout layout = new GridBagLayout ();
         // Define fonts to be used
         Font labelFont = new Font("Arial",Font.PLAIN,12);
         Font buttonFont = new Font("Arial",Font.BOLD,13);
         // Define labels
         JLabel lbUser      = new JLabel("Enter User ID: " );
         JLabel lbPassword      = new JLabel("Enter Password: ");
         JLabel lbSelectName      = new JLabel("Search Name: " );
         JLabel lbFirstName      = new JLabel("First Name: " );
         JLabel lbLastName      = new JLabel("Last Name: " );
         JLabel lbAddress           = new JLabel("Address: " );
         JLabel lbCity           = new JLabel("City" );
         JLabel lbState           = new JLabel("State: " );
         JLabel lbPostcode      = new JLabel("Postcode" );
    JLabel lbCountry           = new JLabel("Country" );
         JLabel lbEmailAddress      = new JLabel("Email Address: " );
    JLabel lbHomeNumber      = new JLabel("Home Phone No.: " );
    JLabel lbFaxNumber      = new JLabel("Fax No.: " );
         // Define combo boxes in third screen (insert pane)
         JComboBox cbName1          = new JComboBox();
         JComboBox cbPersonId1          = new JComboBox();
         // Define combo boxes in second (update/delete pane)
         JComboBox cbName2          = new JComboBox();
         JComboBox cbPersonId2          = new JComboBox();
         // Define buttons, text fields and password field
         JButton btLogin      = new JButton (login );
         JButton btInsert = new JButton (insert );
         JButton btUpdate      = new JButton (update );
         JButton btDelete      = new JButton (delete );
         JButton btInquire      = new JButton (inquire);
         JButton btClear      = new JButton (clear );
         JPasswordField jpPassword           = new JPasswordField(10 );
         JTextField tfUser           = new JTextField("",10 );
         // Inquiry fields on first screen (inquiry pane)
         JTextField tfFirstName1      = new JTextField("",30);
         JTextField tfLastName1           = new JTextField("",30);
         JTextField      tfAddress1          = new JTextField("",30);
         JTextField      tfCity1 = new JTextField("",15);
         JTextField      tfState1 = new JTextField("",15);
         JTextField      tfPostcode1      = new JTextField("",30);
         JTextField      tfCountry1          = new JTextField("",15 );
    JTextField      tfEmailAddress1      = new JTextField("",30);
    JTextField      tfHomeNumber1      = new JTextField("",15);
         JTextField      tfFaxNumber1           = new JTextField("",15 );
         // Input fields on second screen (update/delete pane)
         JTextField tfFirstName2      = new JTextField("",30);
         JTextField tfLastName2          = new JTextField("",30);
         JTextField      tfAddress2          = new JTextField("",30);
         JTextField      tfCity2 = new JTextField("",15);
         JTextField      tfState2 = new JTextField("",15);
         JTextField      tfPostcode2      = new JTextField("",30);
         JTextField      tfCountry2          = new JTextField("",15 );
    JTextField      tfEmailAddress2      = new JTextField("",30);
    JTextField      tfHomeNumber2      = new JTextField("",15);
         JTextField      tfFaxNumber2      = new JTextField("",15 );
         // Input fields on third screen (insert pane)
         JTextField tfFirstName3      = new JTextField("",30);
         JTextField tfLastName3          = new JTextField("",30);
         JTextField      tfAddress3          = new JTextField("",30);
         JTextField      tfCity3 = new JTextField("",15);
         JTextField      tfState3 = new JTextField("",15);
         JTextField      tfPostcode3      = new JTextField("",30);
         JTextField      tfCountry3          = new JTextField("",15 );
    JTextField      tfEmailAddress3      = new JTextField("",30);
    JTextField      tfHomeNumber3      = new JTextField("",15);
         JTextField      tfFaxNumber3           = new JTextField("",15 );
    //------------------------------------------------------------------------------>>>
    //-----------------------Start Addressbook()------------------------------------>>>
    Addressbook(){
    // define listener after adding items to CB to avoid triggering it
         //     cbName1.addItemListener(new ItemListener());
    // public void itemStateChanged(ItemEvent e){
    //--------------------------END Addressbook constructor------------------------------------->>>
    //------------------------------------------------------------------------------>>>
    //------------------------------------------------------------------------------>>>
    //--------------------Start setupLoginPanel()----------------------------------->>>
         // Setup the login screen
         public void setupLoginPanel(){
              // set application title
         setTitle("Address Book Application");
              // center screen
              setLocation((Toolkit.getDefaultToolkit().getScreenSize().width
                                  - getWidth())/2,
                        (Toolkit.getDefaultToolkit().getScreenSize().height
                             - getHeight())/2);
         panel1 = new JPanel();
              // set screen border
              panel1.setBorder(BorderFactory.createTitledBorder(
                                  BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab_login, panel1);
              // add panel to container
              cntr.add(tpane);
              // setup layout as GridBagLayout
              constraints.insets = new Insets(2,2,2,2);
              panel1.setLayout(layout);
              // setup User ID label in display area
              lbUser.setFont(labelFont);
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 0;
              constraints.gridy = 0;
              constraints.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbUser, constraints);
              panel1.add(lbUser);
              // setup User ID input field in display area
              tfUser.setFont(labelFont);
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 1;
              constraints.gridy = 0;
              constraints.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(tfUser, constraints);
              panel1.add(tfUser);
              // setup Password label in display area
              lbPassword.setFont(labelFont);
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 0;
              constraints.gridy = 1;
              constraints.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbPassword, constraints);
              panel1.add(lbPassword);
              // setup Password input field in display area
              jpPassword.setEchoChar('*');
              constraints.ipadx = 2;
              constraints.ipady = 2;
              constraints.gridx = 1;
              constraints.gridy = 1;
              layout.setConstraints(jpPassword, constraints);
              panel1.add(jpPassword);
              // setup Login button in display area
              btLogin.setFont(buttonFont);
              constraints.anchor = GridBagConstraints.WEST;
              constraints.gridy = 3;
              constraints.gridx = 1;
              layout.setConstraints(btLogin, constraints);
              panel1.add(btLogin);
              // setup login button listener
              btLogin.addActionListener(new ButtonHandler());
              // allow ALT L to press login button
              btLogin.setMnemonic('l');
    //--------------------End setupLoginPanel()------------------------------------->>>
    //--------------------Start login()--------------------------------------------->>>
         // Validate user input from the login screen based on information from login
         // table (note: manually create/update your login from table LOGIN).
         public void login(){
              String user = tfUser.getText();
              user = user.trim();
              char[] pw = jpPassword.getPassword();
    String password = new String(pw).trim();
              sql = "SELECT * FROM persons WHERE username='"+
                   user+"' AND password='"+password+"'";
              try{
                   // load MS Access driver
                   Class.forName(driver);
              }catch(java.lang.ClassNotFoundException ex){
                   JOptionPane.showMessageDialog(null,ex.getMessage(), error ,
                        JOptionPane.PLAIN_MESSAGE);
              try{
                   // setup connection to DBMS
                   Connection conn = DriverManager.getConnection(url);
                   // create statement
                   Statement stmt = conn.createStatement();
                   // execute sql statement
                   stmt.execute(sql);
                   ResultSet rs = stmt.getResultSet();
                   boolean recordfound = rs.next();
                   if (recordfound){
                        tpane.removeTabAt(0);
                        showPane1();
                        showPane2();
                        showPane3();
                   else{
                        // username/password invalid
                        JOptionPane.showMessageDialog(null,relogin, error,
                             JOptionPane.INFORMATION_MESSAGE);
                        //clear login and password fields
                        tfUser.setText ("");
                        jpPassword.setText("");
                   conn.close();
              }catch(Exception ex){
                   JOptionPane.showMessageDialog(null,ex.getMessage(), genexception,
                        JOptionPane.INFORMATION_MESSAGE);
    //--------------------End login()----------------------------------------------->>>
    //--------------------Start showPane1()----------------------------------------->>>
         // Setup screen 1(inquiry pane) including labels, input fields, comboboxes.
         // Table PERSONS is read to list inquiry parameters.
         void showPane1(){
              panel1 = new JPanel();
              cbpanel1 = new JPanel();
              // set screen border
              panel1.setBorder(BorderFactory.createTitledBorder(
                                  BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab1, panel1);
              // setup layout as GridBagLayout
              constraints1.insets = new Insets(2,2,2,2);
              panel1.setLayout (layout);
              cbpanel1.setLayout (layout);
              // setup Name combobox label
              lbSelectName.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 0;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbSelectName, constraints1);
              panel1.add(lbSelectName);
              // setup Name combobox as search key
              cbName1.setFont(labelFont);
              constraints1.ipady = 10;
              constraints1.gridx = 1;
              constraints1.gridy = 0;
              constraints1.gridwidth = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(cbName1, constraints1);
              panel1.add(cbName1);
              // setup search combobox (Name and corresponding key)
              cbName1.addItem ("Choose one:");
              cbPersonId1.addItem("0");
              // setup First Name label in display area
              lbFirstName.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.NONE;
              constraints1.gridwidth = 1;
              layout.setConstraints(lbFirstName, constraints1);
              panel1.add(lbFirstName);
              // setup First Name input field in display area
              tfFirstName1.setFont(labelFont);
              tfFirstName1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFirstName1, constraints1);
              panel1.add(tfFirstName1);
              // setup Last Name label in display area
              lbLastName.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.NONE;
              layout.setConstraints(lbLastName, constraints1);
              panel1.add(lbLastName);
              // setup Last Name input field in display area
              tfLastName1.setFont(labelFont);
              tfLastName1.setEditable(false);
              constraints1.gridx = 3;
              constraints1.gridy = 1;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfLastName1, constraints1);
              panel1.add(tfLastName1);
              // setup Address label in display area
              lbAddress.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 2;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbAddress, constraints1);
              panel1.add(lbAddress);
              // setup Address input field in display area
              tfAddress1.setFont(labelFont);
              tfAddress1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 2;
              constraints1.gridwidth = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              constraints1.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(tfAddress1, constraints1);
              panel1.add(tfAddress1);
              // setup City label in display area
              lbCity.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCity, constraints1);
              panel1.add(lbCity);
              // setup City input field in display area
              tfCity1.setFont(labelFont);
              tfCity1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCity1, constraints1);
              panel1.add(tfCity1);
              // setup State label in display area
              lbState.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbState, constraints1);
              panel1.add(lbState);
              // setup State input field in display area
              tfState1.setFont(labelFont);
              tfState1.setEnabled(false);
              constraints1.gridx = 3;
              constraints1.gridy = 3;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfState1, constraints1);
              panel1.add(tfState1);
              // setup Postcode label in display area
              lbPostcode.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbPostcode, constraints1);
              panel1.add(lbPostcode);
              // setup Address input field in display area
              tfPostcode1.setFont(labelFont);
              tfPostcode1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfPostcode1, constraints1);
              panel1.add(tfPostcode1);
              // setup Country label in display area
              lbCountry.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCountry, constraints1);
              panel1.add(lbCountry);
              // setup Country input field in display area
              tfCountry1.setFont(labelFont);
              tfCountry1.setEditable(false);
              constraints1.gridx = 3;
              constraints1.gridy = 4;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCountry1, constraints1);
              panel1.add(tfCountry1);
              // setup Email Address label in display area
              lbEmailAddress = new JLabel ("Email Address:");
              lbEmailAddress.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbEmailAddress, constraints1);
              panel1.add(lbEmailAddress);
              // setup Email Address input field in display area
              tfEmailAddress1.setFont(labelFont);
              constraints1.gridx = 1;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfEmailAddress1, constraints1);
              panel1.add(tfEmailAddress1);
              // setup Home Phone Number label in display area
              lbHomeNumber.setFont(labelFont);
              constraints1.gridx = 2;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbHomeNumber, constraints1);
              panel1.add(lbHomeNumber);
              // setup Home Phone Number input field in display area
              tfHomeNumber1.setFont(labelFont);
              tfHomeNumber1.setEditable(false);
              constraints1.gridx = 3;
              constraints1.gridy = 5;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfHomeNumber1, constraints1);
              panel1.add(tfHomeNumber1);
              // setup Fax Number label in display area
              lbFaxNumber.setFont(labelFont);
              constraints1.gridx = 0;
              constraints1.gridy = 6;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbFaxNumber, constraints1);
              panel1.add(lbFaxNumber);
              // setup Fax Number input field in display area
              tfFaxNumber1.setFont(labelFont);
              tfFaxNumber1.setEditable(false);
              constraints1.gridx = 1;
              constraints1.gridy = 6;
              constraints1.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFaxNumber1, constraints1);
              panel1.add(tfFaxNumber1);
    // indicate inquiry pane
              pane_number = 1;
              // read table get the list of names in CB search key
         accessDBInit();
              // define listener after adding items to CB to avoid triggering it
              cbName1.addItemListener(new ComboBoxHandler());
    //--------------------End showPane1()------------------------------------------->>>
    //--------------------Start showPane2()----------------------------------------->>>
         // Setup screen 2(update and delete pane) including labels, input fields,
         // comboboxes, and buttons. Table PERSONS is read to list inquiry parameters.
         void showPane2(){
              panel2 = new JPanel();
              cbpanel2 = new JPanel();
              labelFont = new Font("Arial",Font.PLAIN,12);
              buttonFont = new Font("Arial",Font.BOLD,12);
              // set screen border
              panel2.setBorder(BorderFactory.createTitledBorder(
                   BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab2, panel2);
              // setup layout as GridBagLayout
              constraints2.insets = new Insets(2,2,2,2);
              panel2.setLayout (layout);
              cbpanel2.setLayout (layout);
              // setup Name combobox label
              lbSelectName.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 0;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbSelectName, constraints2);
              panel1.add(lbSelectName);
              // setup Name combobox as search key
              cbName2.setFont(labelFont);
              constraints2.ipady = 10;
              constraints2.gridx = 1;
              constraints2.gridy = 0;
              constraints2.gridwidth = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(cbName1, constraints2);
              panel1.add (cbName1);
              // setup search combobox (Name and corresponding key)
              cbName1.addItem ("Choose one:");
              cbPersonId1.addItem("0");
              // setup First Name label in display area
              lbFirstName.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.NONE;
              constraints2.gridwidth = 1;
              layout.setConstraints(lbFirstName, constraints2);
              panel1.add(lbFirstName);
              // setup First Name input field in display area
              tfFirstName2.setFont(labelFont);
              tfFirstName2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFirstName2, constraints2);
              panel1.add(tfFirstName2);
              // setup Last Name label in display area
              lbLastName.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.NONE;
              layout.setConstraints(lbLastName, constraints2);
              panel1.add(lbLastName);
              // setup Last Name input field in display area
              tfLastName2.setFont(labelFont);
              tfLastName2.setEditable(false);
              constraints2.gridx = 3;
              constraints2.gridy = 1;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfLastName2, constraints2);
              panel1.add(tfLastName2);
              // setup Address label in display area
              lbAddress.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 2;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbAddress, constraints2);
              panel1.add(lbAddress);
              // setup Address input field in display area
              tfAddress2.setFont(labelFont);
              tfAddress2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 2;
              constraints2.gridwidth = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              constraints2.fill = GridBagConstraints.HORIZONTAL;
              layout.setConstraints(tfAddress2, constraints2);
              panel1.add(tfAddress2);
              // setup City label in display area
              lbCity.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCity, constraints2);
              panel1.add(lbCity);
              // setup City input field in display area
              tfCity2.setFont(labelFont);
              tfCity2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCity2, constraints2);
              panel1.add(tfCity2);
              // setup State label in display area
              lbState.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbState, constraints2);
              panel1.add(lbState);
              // setup State input field in display area
              tfState2.setFont(labelFont);
              tfState2.setEnabled(false);
              constraints2.gridx = 3;
              constraints2.gridy = 3;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfState2, constraints2);
              panel1.add(tfState2);
              // indicate inquiry pane
              pane_number = 1;
              // setup Address label in display area
              lbPostcode.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbPostcode, constraints2);
              panel1.add(lbPostcode);
              // setup Address input field in display area
              tfPostcode2.setFont(labelFont);
              tfPostcode2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfPostcode2, constraints2);
              panel1.add(tfPostcode2);
              // setup Country label in display area
              lbCountry.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbCountry, constraints2);
              panel1.add(lbCountry);
              // setup Country input field in display area
              tfCountry2.setFont(labelFont);
              tfCountry2.setEditable(false);
              constraints2.gridx = 3;
              constraints2.gridy = 4;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfCountry2, constraints2);
              panel1.add(tfCountry2);
              // setup Email Address label in display area
              lbEmailAddress = new JLabel ("Email Address:");
              lbEmailAddress.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbEmailAddress, constraints2);
              panel1.add(lbEmailAddress);
              // setup Email Address input field in display area
              tfEmailAddress2.setFont(labelFont);
              constraints2.gridx = 1;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfEmailAddress2, constraints2);
              panel1.add(tfEmailAddress2);
              // setup Home Phone Number label in display area
              lbHomeNumber.setFont(labelFont);
              constraints2.gridx = 2;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbHomeNumber, constraints2);
              panel1.add(lbHomeNumber);
              // setup Home Phone Number input field in display area
              tfHomeNumber2.setFont(labelFont);
              tfHomeNumber2.setEditable(false);
              constraints2.gridx = 3;
              constraints2.gridy = 5;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfHomeNumber2, constraints2);
              panel1.add(tfHomeNumber2);
              // setup Fax Number label in display area
              lbFaxNumber.setFont(labelFont);
              constraints2.gridx = 0;
              constraints2.gridy = 6;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbFaxNumber, constraints2);
              panel1.add(lbFaxNumber);
              // setup Fax Number input field in display area
              tfFaxNumber2.setFont(labelFont);
              tfFaxNumber2.setEditable(false);
              constraints2.gridx = 1;
              constraints2.gridy = 6;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFaxNumber2, constraints2);
              panel1.add(tfFaxNumber2);
              // setup UPDATE button in display area
              btUpdate.setFont(buttonFont);
              constraints2.gridx = 3;
              constraints2.gridy = 7;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(btUpdate, constraints2);
              panel2.add(btUpdate);
              // setup DELETE button in display area
              btDelete.setFont(buttonFont);
              constraints2.gridx = 1;
              constraints2.gridy = 7;
              constraints2.anchor = GridBagConstraints.WEST;
              layout.setConstraints(btDelete, constraints2);
              panel2.add(btDelete);
              btUpdate.addActionListener(new ButtonHandler());
              btDelete.addActionListener(new ButtonHandler());
              // allow ALT U to press update button
              btUpdate.setMnemonic('u');
              // allow ALT D to press delete button
              btDelete.setMnemonic('d');
              // read table get the list of names in combo box search key
    accessDBInit();
              // define listener after adding items to CB to avoid triggering it
              cbName2.addItemListener(new ComboBoxHandler());
    //--------------------End showPane2()------------------------------------------->>>
    //--------------------Start showPane3()----------------------------------------->>>
         // Setup screen 2(insert pane) including labels, input fields, comboboxes,
         // and buttons.
         void showPane3(){
              panel3      = new JPanel();
              // set screen border
              panel3.setBorder(BorderFactory.createTitledBorder(
                   BorderFactory.createEtchedBorder(),""));
              // add tabbedpane to panel
              tpane.addTab(tab3, panel3);
              // setup layout as GridBagLayout
              constraints3.insets = new Insets(2,2,2,2);
              panel3.setLayout (layout);
              // setup First Name label in display area
              JLabel lbFirstName = new JLabel("First Name:");
              lbFirstName.setFont(labelFont);
              constraints3.gridx = 0;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbFirstName, constraints3);
              panel3.add(lbFirstName);
              // setup First Name input field in display area
              tfFirstName3.setFont(labelFont);
              constraints3.ipady = 8; // adjust heigth of input field
              constraints3.gridx = 1;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfFirstName3, constraints3);
              panel3.add(tfFirstName3);
              // setup Last Name label in display area
              lbLastName = new JLabel("Last Name: ");
              lbLastName.setFont(labelFont);
              constraints3.gridx = 2;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(lbLastName, constraints3);
              panel3.add(lbLastName);
              // setup Last Name input field in display area
              tfLastName3.setFont(labelFont);
              constraints3.gridx = 3;
              constraints3.gridy = 0;
              constraints3.anchor = GridBagConstraints.WEST;
              layout.setConstraints(tfLastName3, constraints3);
              panel3.add(tfLastName3);
              // setup Middle Name label in display area
              lbAddress = new JLabel("Address: ");
              lbAddress.setFont(labelFont);
              constraints3.gridx = 0;
              constraints3.gridy = 1;
              constraints3.anch

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class andy extends JFrame {
      // Define constant variables
      final static String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
      final static String url = "jdbc:odbc:addBKTAFE";
      final static String login = "LOG-IN";
      final static String tab_login = "Log-in";
      final static String tab1 = "INQUIRE Personnel Details";
      final static String tab2 = "UPDATE/DELETE Personnel Details";
      final static String tab3 = "INSERT Personnel Details";
      final static String tab4 = "PRINT";
      final static String insert = "SAVE RECORD";
      final static String update = "UPDATE RECORD";
      final static String delete = "DELETE RECORD";
      final static String inquire = "INQUIRE RECORD";
      final static String clear = " CLEAR ";
      final static String relogin = "Log-in failed! Please relog-in!";
      final static String norecfound = "No Record Found!";
      final static String recinserted = "Record Inserted!";
      final static String recupdated = "Record Updated!";
      final static String recdeleted = "Record Deleted!";
      final static String numericerror = "Age should be numeric!";
      final static String information = "INFORMATION";
      final static String error = "ERROR";
      final static String genexception = "GENERAL EXCEPTION";
      final static String sqlexception = "SQL EXCEPTION";
      final static String confdelete = "CONFIRM DELETE";
      final static String slash = "/";
      final static String table1 = "persons";
      final static String table2 = "Addresses";
      // Define container, panels and tabbedpane
      Container cntr = getContentPane();
      JTabbedPane tpane = new JTabbedPane();
      JPanel cbpanel1 , cbpanel2 , cbpanel3,
             panel1 , panel2 , panel3, panel4;
      // Define fonts to be used
      Font labelFont = new Font("Arial",Font.PLAIN,12);
      Font buttonFont = new Font("Arial",Font.BOLD,13);
      // Define labels
      JLabel lbUser = new JLabel("Enter User ID: " );
      JLabel lbPassword = new JLabel("Enter Password: ");
      JLabel lbSelectName = new JLabel("Search Name: " );
      JLabel lbFirstName = new JLabel("First Name: " );
      JLabel lbLastName = new JLabel("Last Name: " );
      JLabel lbAddress = new JLabel("Address: " );
      JLabel lbCity = new JLabel("City: " );
      JLabel lbState = new JLabel("State: " );
      JLabel lbPostcode = new JLabel("Postcode: " );
      JLabel lbCountry = new JLabel("Country: " );
      JLabel lbEmailAddress = new JLabel("Email Address: " );
      JLabel lbHomeNumber = new JLabel("Home Phone No.: " );
      JLabel lbFaxNumber = new JLabel("Fax No.: " );
      // Define combo boxes in third screen (insert pane)
      JComboBox cbName1     = new JComboBox();
      JComboBox cbName2     = new JComboBox();
      JComboBox cbName3     = new JComboBox();
      JComboBox cbPersonId1 = new JComboBox();
      JComboBox cbPersonId2 = new JComboBox();
      JComboBox cbPersonId3 = new JComboBox();
      // Inquiry fields on first screen (inquiry pane)
      JTextField tfFirstName1 = new JTextField("",30);
      JTextField tfLastName1 = new JTextField("",30);
      JTextField tfAddress1 = new JTextField("",30);
      JTextField tfCity1 = new JTextField("",15);
      JTextField tfState1 = new JTextField("",15);
      JTextField tfPostcode1 = new JTextField("",30);
      JTextField tfCountry1 = new JTextField("",15 );
      JTextField tfEmailAddress1 = new JTextField("",30);
      JTextField tfHomeNumber1 = new JTextField("",15);
      JTextField tfFaxNumber1 = new JTextField("",15 );
      // Input fields on second screen (update/delete pane)
      JTextField tfFirstName2 = new JTextField("",30);
      JTextField tfLastName2 = new JTextField("",30);
      JTextField tfAddress2 = new JTextField("",30);
      JTextField tfCity2 = new JTextField("",15);
      JTextField tfState2 = new JTextField("",15);
      JTextField tfPostcode2 = new JTextField("",30);
      JTextField tfCountry2 = new JTextField("",15);
      JTextField tfEmailAddress2 = new JTextField("",30);
      JTextField tfHomeNumber2 = new JTextField("",15);
      JTextField tfFaxNumber2 = new JTextField("",15);
      // Input fields on third screen (inset details pane)
      JTextField tfFirstName3 = new JTextField("",30);
      JTextField tfLastName3 = new JTextField("",30);
      JTextField tfAddress3 = new JTextField("",30);
      JTextField tfCity3 = new JTextField("",15);
      JTextField tfState3 = new JTextField("",15);
      JTextField tfPostcode3 = new JTextField("",30);
      JTextField tfCountry3 = new JTextField("",15);
      JTextField tfEmailAddress3 = new JTextField("",30);
      JTextField tfHomeNumber3 = new JTextField("",15);
      JTextField tfFaxNumber3 = new JTextField("",15);
      GridBagLayout layout = new GridBagLayout();
      GridBagConstraints constraints = new GridBagConstraints();
      public andy() {
        super("Address Book Application");
        showPane1();
        showPane2();
        showPane3();
        showPane4();
        cntr.add(tpane, "Center");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(900,385);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setLocation((screenSize.width  - getWidth())/2,
                    (screenSize.height - getHeight())/2);
        setVisible(true);
      // Setup screen 1(inquiry pane) including labels, input fields, comboboxes.
      // Table PERSONS is read to list inquiry parameters.
      void showPane1() {
        panel1 = new JPanel();
        cbpanel1 = new JPanel();
        // set screen border
        panel1.setBorder(BorderFactory.createTitledBorder(
          BorderFactory.createEtchedBorder(),""));
        // add tabbedpane to panel
        tpane.addTab(tab1, panel1);
        // setup layout as GridBagLayout
        constraints.insets = new Insets(2,2,2,2);
        panel1.setLayout (layout);
        cbpanel1.setLayout (layout);
        // setup Name combobox label
        lbSelectName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbSelectName, constraints);
        panel1.add(lbSelectName);
        // setup Name combobox as search key
        cbName1.setFont(labelFont);
        constraints.ipady = 10;
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(cbName1, constraints);
        panel1.add(cbName1);
        // setup search combobox (Name and corresponding key)
        cbName1.addItem ("Choose one:");
        cbPersonId1.addItem("0");
        // setup First Name label in display area
        lbFirstName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFirstName, constraints);
        panel1.add(lbFirstName);
        // setup First Name input field in display area
        tfFirstName1.setFont(labelFont);
        tfFirstName1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFirstName1, constraints);
        panel1.add(tfFirstName1);
        // setup Last Name label in display area
        lbLastName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbLastName, constraints);
        panel1.add(lbLastName);
        // setup Last Name input field in display area
        tfLastName1.setFont(labelFont);
        tfLastName1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfLastName1, constraints);
        panel1.add(tfLastName1);
        // setup Address label in display area
        lbAddress.setFont(labelFont);
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbAddress, constraints);
        panel1.add(lbAddress);
        // setup Address input field in display area
        tfAddress1.setFont(labelFont);
        tfAddress1.setEditable(false);
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.weightx = 1.0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        layout.setConstraints(tfAddress1, constraints);
        panel1.add(tfAddress1);
        // setup City label in display area
        lbCity.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        constraints.fill = GridBagConstraints.NONE;
            layout.setConstraints(lbCity, constraints);
        panel1.add(lbCity);
        // setup City input field in display area
        tfCity1.setFont(labelFont);
        tfCity1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfCity1, constraints);
        panel1.add(tfCity1);
        // setup State label in display area
        lbState.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbState, constraints);
        panel1.add(lbState);
        // setup State input field in display area
        tfState1.setFont(labelFont);
        tfState1.setEnabled(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfState1, constraints);
        panel1.add(tfState1);
        // setup Postcode label in display area
        lbPostcode.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbPostcode, constraints);
        panel1.add(lbPostcode);
        // setup Address input field in display area
        tfPostcode1.setFont(labelFont);
        tfPostcode1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfPostcode1, constraints);
        panel1.add(tfPostcode1);
        // setup Country label in display area
        lbCountry.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbCountry, constraints);
        panel1.add(lbCountry);
        // setup Country input field in display area
        tfCountry1.setFont(labelFont);
        tfCountry1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfCountry1, constraints);
        panel1.add(tfCountry1);
        // setup Email Address label in display area
        lbEmailAddress.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbEmailAddress, constraints);
        panel1.add(lbEmailAddress);
        // setup Email Address input field in display area
        tfEmailAddress1.setFont(labelFont);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfEmailAddress1, constraints);
        panel1.add(tfEmailAddress1);
        // setup Home Phone Number label in display area
        lbHomeNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbHomeNumber, constraints);
        panel1.add(lbHomeNumber);
        // setup Home Phone Number input field in display area
        tfHomeNumber1.setFont(labelFont);
        tfHomeNumber1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfHomeNumber1, constraints);
        panel1.add(tfHomeNumber1);
        // setup Fax Number label in display area
        lbFaxNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFaxNumber, constraints);
        panel1.add(lbFaxNumber);
        // setup Fax Number input field in display area
        tfFaxNumber1.setFont(labelFont);
        tfFaxNumber1.setEditable(false);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFaxNumber1, constraints);
        panel1.add(tfFaxNumber1);
        // indicate inquiry pane
        // pane_number = 1;
        // read table get the list of names in CB search key
        // accessDBInit();
        // define listener after adding items to CB to avoid triggering it
        // cbName1.addItemListener(new ComboBoxHandler());
      //--------------------End showPane1()------------------------------------------->>>
      //--------------------Start showPane2()----------------------------------------->>>
      void showPane2() {
        panel2 = new JPanel();
        cbpanel2 = new JPanel();
        // set screen border
        panel2.setBorder(BorderFactory.createTitledBorder(
          BorderFactory.createEtchedBorder(),""));
        // add tabbedpane to panel
        tpane.addTab(tab2, panel2);
        // setup layout as GridBagLayout
        constraints.ipady = 0;
        panel2.setLayout (layout);
        cbpanel2.setLayout (layout);
        // setup Name combobox label
        lbSelectName = new JLabel("Search Name: ");
        lbSelectName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbSelectName, constraints);
        panel2.add(lbSelectName);
        // setup Name combobox as search key
        cbName2.setFont(labelFont);
        constraints.ipady = 10;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(cbName2, constraints);
        panel2.add(cbName2);
        // setup search combobox (Name and corresponding key)
        cbName2.addItem ("Choose one:");
        cbPersonId2.addItem("0");
        // setup UPDATE button in display area
        JButton btUpdate = new JButton("Update");
        btUpdate.setFont(buttonFont);
    //    btUpdate.addActionListener(new ButtonHandler());
        btUpdate.setMnemonic(KeyEvent.VK_U);
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(btUpdate, constraints);
        panel2.add(btUpdate);
        // setup DELETE button in display area
        JButton btDelete = new JButton("Delete");
        btDelete.setFont(buttonFont);
    //    btDelete.addActionListener(new ButtonHandler());
        btDelete.setMnemonic(KeyEvent.VK_D);
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(btDelete, constraints);
        panel2.add(btDelete);
        // setup First Name label in display area
        lbFirstName = new JLabel("First Name: ");
        lbFirstName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFirstName, constraints);
        panel2.add(lbFirstName);
        // setup First Name input field in display area
        tfFirstName2.setFont(labelFont);
        tfFirstName2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFirstName2, constraints);
        panel2.add(tfFirstName2);
        // setup Last Name label in display area
        lbLastName = new JLabel("Last Name: ");
        lbLastName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbLastName, constraints);
        panel2.add(lbLastName);
        // setup Last Name input field in display area
        tfLastName2.setFont(labelFont);
        tfLastName2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfLastName2, constraints);
        panel2.add(tfLastName2);
        // setup Address label in display area
        lbAddress = new JLabel("Address: ");
        lbAddress.setFont(labelFont);
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbAddress, constraints);
        panel2.add(lbAddress);
        // setup Address input field in display area
        tfAddress2.setFont(labelFont);
        tfAddress2.setEditable(true);
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.weightx = 1.0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        layout.setConstraints(tfAddress2, constraints);
        panel2.add(tfAddress2);
        // setup City label in display area
        lbCity = new JLabel("City: ");
        lbCity.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        constraints.fill = GridBagConstraints.NONE;
        layout.setConstraints(lbCity, constraints);
        panel2.add(lbCity);
        // setup City input field in display area
        tfCity2.setFont(labelFont);
        tfCity2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfCity2, constraints);
        panel2.add(tfCity2);
        // setup State label in display area
        lbState = new JLabel("State: ");
        lbState.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbState, constraints);
        panel2.add(lbState);
        // setup State input field in display area
        tfState2.setFont(labelFont);
        tfState2.setEnabled(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfState2, constraints);
        panel2.add(tfState2);
        // setup Postcode label in display area
        lbPostcode = new JLabel("Postcode: ");
        lbPostcode.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbPostcode, constraints);
        panel2.add(lbPostcode);
        // setup Address input field in display area
        tfPostcode2.setFont(labelFont);
        tfPostcode2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfPostcode2, constraints);
        panel2.add(tfPostcode2);
        // setup Country label in display area
        lbCountry = new JLabel("Country: ");
        lbCountry.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbCountry, constraints);
        panel2.add(lbCountry);
        // setup Country input field in display area
        tfCountry2.setFont(labelFont);
        tfCountry2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfCountry2, constraints);
        panel2.add(tfCountry2);
        // setup Email Address label in display area
        lbEmailAddress = new JLabel ("Email Address: ");
        lbEmailAddress.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbEmailAddress, constraints);
        panel2.add(lbEmailAddress);
        // setup Email Address input field in display area
        tfEmailAddress2.setFont(labelFont);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfEmailAddress2, constraints);
        panel2.add(tfEmailAddress2);
        // setup Home Phone Number label in display area
        lbHomeNumber = new JLabel("Home Phone No.: ");
        lbHomeNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbHomeNumber, constraints);
        panel2.add(lbHomeNumber);
        // setup Home Phone Number input field in display area
        tfHomeNumber2.setFont(labelFont);
        tfHomeNumber2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfHomeNumber2, constraints);
        panel2.add(tfHomeNumber2);
        // setup Fax Number label in display area
        lbFaxNumber = new JLabel("Fax No.: ");
        lbFaxNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFaxNumber, constraints);
        panel2.add(lbFaxNumber);
        // setup Fax Number input field in display area
        tfFaxNumber2.setFont(labelFont);
        tfFaxNumber2.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFaxNumber2, constraints);
        panel2.add(tfFaxNumber2);
      //-----------------------------End showpane2()---------------------------------->>
      //--------------------Start showPane3()----------------------------------------->>>
      void showPane3() {
        panel3 = new JPanel();
        // cbpanel3 = new JPanel();
        // set screen border
        panel3.setBorder(BorderFactory.createTitledBorder(
          BorderFactory.createEtchedBorder(),""));
        // add tabbedpane to panel
        tpane.addTab(tab3, panel3);
        // setup layout as GridBagLayout
        panel3.setLayout(layout);
        constraints.ipady = 0;
        panel3.setLayout (layout);
        // cbpanel3.setLayout (layout);
        // setup Name combobox label
        lbSelectName = new JLabel("Search Name: ");
        lbSelectName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbSelectName, constraints);
        panel3.add(lbSelectName);
        // setup Name combobox as search key
        cbName3 = new JComboBox();
        cbName3.setFont(labelFont);
        constraints.ipady = 10;
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(cbName3, constraints);
        panel3.add(cbName3);
        // setup search combobox (Name and corresponding key)
        cbName3.addItem ("Choose one:");
        cbPersonId3.addItem("0");
        // setup INSERT button in display area
        JButton btInsert = new JButton("Insert");
        btInsert.setFont(buttonFont);
    //    btInsert.addActionListener(new ButtonListener());
        btInsert.setMnemonic(KeyEvent.VK_S);
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(btInsert, constraints);
        panel3.add(btInsert);
        // setup CLEAR button in display area
        JButton btClear = new JButton("Clear");
        btClear.setFont(buttonFont);
    //    btClear.addActionListener(new ButtonListener());
        btClear.setMnemonic(KeyEvent.VK_C);
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(btClear, constraints);
        panel3.add(btClear);
        // setup First Name label in display area
        lbFirstName = new JLabel("First Name: ");
        lbFirstName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFirstName, constraints);
        panel3.add(lbFirstName);
        // setup First Name input field in display area
        tfFirstName3.setFont(labelFont);
        tfFirstName3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFirstName3, constraints);
        panel3.add(tfFirstName3);
        // setup Last Name label in display area
        lbLastName = new JLabel("Last Name: ");
        lbLastName.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbLastName, constraints);
        panel3.add(lbLastName);
        // setup Last Name input field in display area
        tfLastName3.setFont(labelFont);
        tfLastName3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfLastName3, constraints);
        panel3.add(tfLastName3);
        // setup Address label in display area
        lbAddress = new JLabel("Address: ");
        lbAddress.setFont(labelFont);
        constraints.gridwidth = 1;
        constraints.anchor = GridBagConstraints.EAST;
        layout.setConstraints(lbAddress, constraints);
        panel3.add(lbAddress);
        // setup Address input field in display area
        tfAddress3.setFont(labelFont);
        tfAddress3.setEditable(true);
        constraints.gridwidth = constraints.REMAINDER;
        constraints.anchor = GridBagConstraints.WEST;
        constraints.weightx = 1.0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        layout.setConstraints(tfAddress3, constraints);
        panel3.add(tfAddress3);
        // setup City label in display area
        lbCity = new JLabel("City: ");
        lbCity.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        constraints.fill = GridBagConstraints.NONE;
        layout.setConstraints(lbCity, constraints);
        panel3.add(lbCity);
        // setup City input field in display area
        tfCity3.setFont(labelFont);
        tfCity3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfCity3, constraints);
        panel3.add(tfCity3);
        // setup State label in display area
        lbState = new JLabel("State: ");
        lbState.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbState, constraints);
        panel3.add(lbState);
        // setup State input field in display area
        tfState3.setFont(labelFont);
        tfState3.setEnabled(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfState3, constraints);
        panel3.add(tfState3);
        // setup Postcode label in display area
        lbPostcode = new JLabel("Postcode: ");
        lbPostcode.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbPostcode, constraints);
        panel3.add(lbPostcode);
        // setup Address input field in display area
        tfPostcode3.setFont(labelFont);
        tfPostcode3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfPostcode3, constraints);
        panel3.add(tfPostcode3);
        // setup Country label in display area
        lbCountry = new JLabel("Country: ");
        lbCountry.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbCountry, constraints);
        panel3.add(lbCountry);
        // setup Country input field in display area
        tfCountry3.setFont(labelFont);
        tfCountry3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfCountry3, constraints);
        panel3.add(tfCountry3);
        // setup Email Address label in display area
        lbEmailAddress = new JLabel ("Email Address: ");
        lbEmailAddress.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbEmailAddress, constraints);
        panel3.add(lbEmailAddress);
        // setup Email Address input field in display area
        tfEmailAddress3.setFont(labelFont);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfEmailAddress3, constraints);
        panel3.add(tfEmailAddress3);
        // setup Home Phone Number label in display area
        lbHomeNumber = new JLabel("Home Phone No.: ");
        lbHomeNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = constraints.RELATIVE;
        layout.setConstraints(lbHomeNumber, constraints);
        panel3.add(lbHomeNumber);
        // setup Home Phone Number input field in display area
        tfHomeNumber3.setFont(labelFont);
        tfHomeNumber3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        constraints.gridwidth = constraints.REMAINDER;
        layout.setConstraints(tfHomeNumber3, constraints);
        panel3.add(tfHomeNumber3);
        // setup Fax Number label in display area
        lbFaxNumber = new JLabel("Fax No.: ");
        lbFaxNumber.setFont(labelFont);
        constraints.anchor = GridBagConstraints.EAST;
        constraints.gridwidth = 1;
        layout.setConstraints(lbFaxNumber, constraints);
        panel3.add(lbFaxNumber);
        // setup Fax Number input field in display area
        tfFaxNumber3.setFont(labelFont);
        tfFaxNumber3.setEditable(true);
        constraints.anchor = GridBagConstraints.WEST;
        layout.setConstraints(tfFaxNumber3, constraints);
        panel3.add(tfFaxNumber3);
      //-----------------------------End showpane3()---------------------------------->>
      //-----------------------------Start showPane4()-------------------------------->>
      void showPane4() {
    //    qtm = new QueryTableModel();
    //    JTable table = new JTable(qtm);
    //    String query = "SELECT FirstName, LastName, HomePhone, " +
    //                   "FROM Addresses ORDER By LastName";
    //    qtm.setQuery(query);
        JPanel demoPanel = new JPanel();
        demoPanel.setPreferredSize(new Dimension(400,500));
        demoPanel.setBackground(Color.pink);
        demoPanel.add(new JLabel("Demo Panel in place of table",
                                  SwingConstants.CENTER));
        JScrollPane scrollPane = new JScrollPane(demoPanel);
        panel4 = new JPanel();
    //    pane_number = 4;
        panel4.setLayout(layout);
        constraints.ipady = 0;
    //    labelFont = new Font("Arial", Font.PLAIN, 12);   defined above
        buttonFont = new Font("Arial", Font.PLAIN, 13);
       // set screen border
       panel4.setBorder(
         BorderFactory.createTitledBorder(
           BorderFactory.createEtchedBorder(), ""));
       // add panel to tabbed pane
       tpane.addTab(tab4, panel4);
       JLabel lbPrint = new JLabel("Print");
       lbPrint.setFont(labelFont);
       constraints.anchor = constraints.EAST;
       layout.setConstraints(lbPrint, constraints);
       panel4.add(lbPrint);
       JButton btPrint = new JButton("Print");
       btPrint.setFont(buttonFont);
    //   btPrint.addActionListener(new ButtonListener());
       btPrint.setMnemonic(KeyEvent.VK_P);
       constraints.anchor = constraints.WEST;
       constraints.gridwidth = constraints.REMAINDER;
       layout.setConstraints(btPrint, constraints);
       panel4.add(btPrint);
       constraints.weighty = 1.0;
       constraints.fill = constraints.BOTH;
       constraints.anchor = constraints.CENTER;
       layout.setConstraints(scrollPane, constraints);
       panel4.add(scrollPane);
      public static void main(String[] args) {
        new andy();
    }

  • Gmail and Google Apps sync with E72 - problem upda...

    Hi
    On my E72 I have set up two mailaccounts: My private Gmail account and my workmail which is a google apps account. Both work great and I have no problem recieving or sending mails.
    My problem is that the inboxes on my phone do not update: When I recieve a new mail in either mailbox and read this mail on my computer, the same email is still unread on my phone.
    Why is this, and how do I make my phone update properly?
    Thanks!
    - Jesper  

    I forgot to write that if I read an email on my phone it actually eventually shows as read on my computer, which makes this even more puzzling...!

  • Problem with jpanel size

    Hi I want to add a view port to a JPanel
    the main problem is that the Jpanel change size as the frame.
    how can i make it independent from the frame so having it; own w, h
    thanks
    package help;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import javax.swing.*;
    public abstract class MyFrame extends JFrame {
    private static final long serialVersionUID = 1L;
    private static JButton drawCircle, drawRectangle, drawSquare, drawStar, start, clear,quit,back, screenshoot;
    static final int FPS_MIN = 0;
    static final int FPS_MAX = 150;
    static final int FPS_INIT = 0;
    static int fps;
    double x1,x2;
    double y1,y2;
    int dr =1;
    int dy= 1;
    int Selection=0;
    boolean click=true; //check if start has been clicked
    int width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;  // screen width
    int height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;     //screen higth
    protected static int count;
    int R,G,B;  //color
    Cursor c;                    //cursor object
    private static ShapePanel bpnl;
    public MyFrame()
            R=G=B=0;
            int width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
            int height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height-100;
            JFrame frame=new JFrame();
            BorderLayout layout=new BorderLayout();
            frame.setLayout(layout);
            frame.setTitle("Game");
            //panel to hold buttons
            JPanel upPanel = new JPanel();
            upPanel.setLayout(new FlowLayout());
            upPanel.setSize(width, height/5);
            //panel to hold SLIDERS
            JPanel leftPanel = new JPanel();
            leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
            leftPanel.setSize(50, height);
            //initialize buttons and add to the upPanel
            drawCircle=new JButton("Draw Circle");
            upPanel.add(drawCircle);
            drawStar=new JButton("Draw Star");
            upPanel.add(drawStar);
            drawRectangle=new JButton("Draw Rectangle");
            upPanel.add(drawRectangle);
            drawSquare=new JButton("Draw Square");
            upPanel.add(drawSquare);
            start=new JButton("Start");
            start.setBackground(Color.GREEN);
            //upPanel.add(start);
            clear=new JButton("Clear");
            upPanel.add(clear);
            back=new JButton("Back");
            upPanel.add(back);
            quit=new JButton("Quit");
            quit.setBackground(Color.red);
            upPanel.add(quit);  
            screenshoot=new JButton("ScreenShoot");
            c = new Cursor (Cursor.CROSSHAIR_CURSOR);     //Change cursor to cross hair
         this.setCursor (c);
            //new object spanel to hold TIMER
            JPanel spanel=new JPanel();
                spanel.setLayout(new GridLayout());
                //slider dimension construction
                JSlider sDimension = new JSlider(JSlider.HORIZONTAL,FPS_MIN, FPS_MAX, FPS_INIT);
                sDimension.setMajorTickSpacing(30);
                sDimension.setMinorTickSpacing(3);
                sDimension.setPaintTicks(true);
                sDimension.setPaintLabels(true);
                Font font = new Font("Serif", Font.ITALIC, 15);
                sDimension.setFont(font);
                sDimension.setBorder(BorderFactory.createTitledBorder("Shape Dimension"));
                //slider speed construction
                int FPS_MIN_s = 0;
                int FPS_MAX_s = 60;
                int FPS_INIT_s = 0;    //initial frames per second
                JSlider sSpeed = new JSlider(JSlider.HORIZONTAL,FPS_MIN_s, FPS_MAX_s, FPS_INIT_s);
                sSpeed.setBorder(BorderFactory.createTitledBorder("Shape Speed"));
             ////////////////////////// // slider colors////////////////////////////////////////////////////
                int FPS_MIN_C = 0;
                int FPS_MAX_C = 250;
                int FPS_INIT_C = 0;  
                JSlider sliderR= new JSlider(JSlider.HORIZONTAL,FPS_MIN_C, FPS_MAX_C, FPS_INIT_C);
                sliderR.setBorder(BorderFactory.createTitledBorder("Red Channel"));
                JSlider sliderG= new JSlider(JSlider.HORIZONTAL,FPS_MIN_C, FPS_MAX_C, FPS_INIT_C);
                sliderG.setMajorTickSpacing(50);
                sliderG.setMinorTickSpacing(25);
                sliderG.setPaintTicks(true);
                sliderG.setPaintLabels(true);
                sliderG.setFont(font);
                sliderG.setBorder(BorderFactory.createTitledBorder("Green Channel"));
                JSlider sliderB= new JSlider(JSlider.HORIZONTAL,FPS_MIN_C, FPS_MAX_C, FPS_INIT_C);
                sliderB.setBorder(BorderFactory.createTitledBorder("Blue Channel"));
              //     spanel.add(sSpeed,BorderLayout.EAST);
                  frame.add(upPanel,BorderLayout.NORTH);
                  frame.add(leftPanel,BorderLayout.WEST);
                  bpnl = new ShapePanel(3000,3000);
                        System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
                        bpnl.setFocusable(true);
                  upPanel.setBackground(Color.DARK_GRAY);
                  upPanel.setBorder(BorderFactory.createLineBorder(Color.white));
            frame.add(spanel,BorderLayout.SOUTH);       
            frame.add(bpnl, BorderLayout.CENTER);
            frame.setSize(width, height);
            frame.setVisible(true);               
               leftPanel.add(sliderR);
               leftPanel.add(sliderB);
               leftPanel.add(sliderG);
               leftPanel.add(sDimension,BorderLayout.WEST); 
                 System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
              public static  int getPanelWidth()
                  System.out.println("panel width   "+bpnl.getWidth());
                  return bpnl.getWidth();
              public static  int getPanelHeigth()
                  System.out.println("Panel heigth  " +bpnl.getHeight());
                  return bpnl.getHeight();
              public static void main(String args[])
                  new MyFrame() {};
    package help;
    import java.awt.Cursor;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    class ShapePanel extends JPanel  {
         private static final long serialVersionUID = 1L;
         private javax.swing.Timer animationTmr;
         private float heigth;
         private float width;
         private Cursor c;
         public ShapePanel(int w, int h) {
                    int W=w;
                    int H=h;
                    c = new Cursor (Cursor.CROSSHAIR_CURSOR);     //Change cursor to cross hair
                    this.setCursor (c); 
                    this.setPreferredSize(3000,3000);
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.fillRect(0, 0, this.getWidth(), this.getHeight());
        private void setPreferredSize(int i, int i0) {
        thanks

    sorry i hope this is better
    package help;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public abstract class MyFrame extends JFrame {
    private static final long serialVersionUID = 1L;
    int dr =1;
    int dy= 1;
    int Selection=0;
    int width = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;  // screen width
    int height = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height-100;     //screen higth
    private static ShapePanel bpnl;
    public MyFrame()
            JFrame frame=new JFrame();
            BorderLayout layout=new BorderLayout();
            frame.setLayout(layout);
            bpnl = new ShapePanel(3000,3000);
            System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
            bpnl.setFocusable(true);
              frame.add(bpnl);
            frame.setSize(width, height);
               pack();
            frame.setVisible(true);               
    System.out.println("panel width = "+bpnl.getWidth() +"  heigth = " + bpnl.getHeight());
              public static  int getPanelWidth()
                  System.out.println("panel width   "+bpnl.getWidth());
                  return bpnl.getWidth();
              public static  int getPanelHeigth()
                  System.out.println("Panel heigth  " +bpnl.getHeight());
                  return bpnl.getHeight();
              public static void main(String args[])
                  new MyFrame() {};
    package help;
    import java.awt.Cursor;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    class ShapePanel extends JPanel  {
         private static final long serialVersionUID = 1L;
         private Cursor c;
         public ShapePanel(int w, int h) {
                    int W=w;
                    int H=h;
                    c = new Cursor (Cursor.CROSSHAIR_CURSOR);     //Change cursor to cross hair
                    this.setCursor (c); 
                    this.setPreferredSize(3000,3000);
         public void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.fillRect(0, 0, this.getWidth(), this.getHeight());
        private void setPreferredSize(int i, int i0) {
       

Maybe you are looking for

  • How to Get xml Attribute value from a given  xpath

    i'm building an xml from 3 columns a,b,c using 'SELECT EXTRACT (XMLELEMENT ("ROOT",.........)' and my xml looks something like this <ROOT> <categories> <catogory value="col a value" display="true"/> <catogory value="col b value" display="false"/> <ca

  • SL Upgrade not ready for prime time - too many issues for no real value

    I am thinking the upgrade to SL was a mistake - On a macbook pro that was running acceptable. Decided to jump on the SL bandwagon....and I am finding reduced battery charge, a service the battery icon, battery times that jump up and down by 20-30 min

  • Word 2007 - documents open in read only mode

    Got a couple of users who are getting this issue. When they want to open some documents from a file share, it opens as read only (this is random)  - comes up with a prompt saying that this file is locked for editing by another user. If they close it,

  • Javascript error when inserting dynamic table in DW

    Hi Im using DW9 (CS3) and have problem. When i klick on the 'dynamic table' button i get this error: While executing insertObject in Dynamic Table.htm, a Javascript error(s) occurred: Any sulution? Please send me a copy fo the reply to my mail: [emai

  • Launch button for PS CC runs 32-bit version of program, not 64-bit version

    I'm starting to get reports from people that after initially installing PS CC that the launch button created during installation launches the 32-bit version of PS CC instead of the 64-bit version.  To check which version you're running, click Help>Ab