Jframe Help

Hi There,I wonder if anyone can help me. I currently have to Jframe displayed in a card layout. I would like to display it as one JFrame, with thediferrent layouts that would normally be in each Jframe put into one frame seperated by a "next" button, rather like a wizard setup. Can anyone give me any advice on how to do this? Here is my code for the JFrame, which is currently displayed twice:
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.UIManager;
public class StartFrame extends JFrame implements ActionListener, ItemListener
      private JComboBox typeOfPlayer;
      JPanel cards; //a panel that uses CardLayout  
      final static String SELECT_USER = "Please select the type of player";
     final static String HUMAN = "Human"; 
     final static String COMPUTER = "Computer";
    private JButton select; 
    private Player play;
    private JComboBox cb; 
   private JTextField name;  
   private boolean isSubmitted;   
public StartFrame(Player p)
      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      setSize(200, 300); 
      play = p;   
      isSubmitted = false;   
  try  
               UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  catch (Exception e) 
              UIManager.getSystemLookAndFeelClassName();    
   //Create and set up the content pane.  
  addComponentToPane(this.getContentPane()); 
  //Display the window.  
  this.pack();   
  this.setVisible(true);
  public void addComponentToPane(Container pane) 
//Put the JComboBox in a JPanel to get a nicer look. 
JPanel comboBoxPane = new JPanel(); //use FlowLayout    
String comboBoxItems[] =      { SELECT_USER, HUMAN, COMPUTER };  
cb = new JComboBox(comboBoxItems); 
cb.setEditable(false);  
cb.addItemListener(this);   
comboBoxPane.add(cb);         
  //Create the "cards".            JPanel card1 = new JPanel();   
  JPanel card2 = new JPanel();  
   String levels[] =      {"Beginner", "intermediate", "expert"};  
   JComboBox levelOfDifficulty = new JComboBox(levels);  
   card2.add(new JLabel("Select Level"));   
  card2.add(levelOfDifficulty);   
  select = new JButton("select");  
   select.addActionListener(this);  
   card2.add(select);          
   JPanel card3 = new JPanel();  
   card3.add(new JLabel("Enter name")); 
   name = new JTextField(20);
   card3.add(name);   
  select = new JButton("select");   
  select.addActionListener(this); 
  card3.add(select);   
//Create the panel that contains the "cards".    
cards = new JPanel(new CardLayout());   
  cards.add(card1, SELECT_USER);
  cards.add(card2, COMPUTER);      cards.add(card3, HUMAN);  
  pane.add(comboBoxPane, BorderLayout.PAGE_START);   
  pane.add(cards, BorderLayout.CENTER); 
public void itemStateChanged(ItemEvent evt)
  CardLayout cl = (CardLayout)(cards.getLayout());
     cl.show(cards, (String)evt.getItem()); 
public void actionPerformed(ActionEvent ae) 
  if(ae.getSource() == select)   
     if (cb.getSelectedItem()=="Human")     
          System.out.println("human");//   
        play = new HumanPlayer();//  
         play.setName(name.getText());     
   else if (cb.getSelectedItem()=="Computer")  
  System.out.println("Computer");  
         play.setName("Computer");         
  isSubmitted = true;
    public boolean getIsSubmitted() 
    return isSubmitted; 
}

Hi,
you can choose from a variety of things but a JTree would be the best.
Regards
Aakash

Similar Messages

  • Question on JFrame, help me plzzzzzzz!!!

    Hi my friend:
    I need your help on JFrame urgently. As we know, we close a JFrame by clicking the close button on the window title pane. Now I want to change this default for my JFrame. So that when someone click the close button, an Joptionpane is pop out to confirm the closing action. The JFrame will only be closed by clicking the "OK" button on the Joptionpane. If click cancel, optionpane disappear. How to do this? Pls guide me.

    close a JFrame by clicking the close button on the
    window title pane. Now I want to change this default
    for my JFrame. 1) http://java.sun.com/j2se/1.3/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)
    So that when someone click the close
    button, an Joptionpane is pop out to confirm the
    closing action. The JFrame will only be closed by
    clicking the "OK" button on the Joptionpane. If click
    cancel, optionpane disappear.2)
    if(JOptionPane.showConfirmDialog(JFrame.this,"Really close?","Confirm Window Closing", JOptionPane.YES_NO_CANCEL_OPTION)==?){
    //do something...
    }the ? means you can figure it out yourself with the documentation...
    http://java.sun.com/j2se/1.3/docs/api/javax/swing/JOptionPane.html

  • Long delay during first resize of visible JFrame (help!)

    I need to increase the size of a component in a visible JFrame (and with it the size of the frame itself). The way I did this using jdk 1.3.1 causes a problem in 1.4.0 and 1.4.1.
    When a component in a visible JFrame (such as a JPanel) is resized - using a setPreferredSize()-pack() sequence, there is a VERY long delay (~ 5 seconds) before the frame is fully redrawn. This only occurs the FIRST time the component is resized. Subsequent setPreferredSize()-pack() sequences take a reasonable amount of time.
    Here's a simple example:
    import java.awt.*;
    import javax.swing.*;
    public class PackDelayTest extends JFrame {
        JPanel pan;
        int width;
        static long tm;
        public static void main(String[] argv) {
                tm = System.currentTimeMillis();
            PackDelayTest2 test = new PackDelayTest();
                elapsed("in constructor");
            test.replace(); elapsed("repack 1");
            test.replace(); elapsed("repack 2");
            test.replace(); elapsed("repack 2");
            test.replace(); elapsed("repack 2");  
            System.exit(0);
        public PackDelayTest() {
            pan = new JPanel();
            pan.setLayout(new BoxLayout(pan,BoxLayout.Y_AXIS));
            getContentPane().add(pan);        
            JLabel label = new JLabel("Label 0");
            pan.add(label);  
            pack();
            setVisible(true);
            width = pan.getPreferredSize().width;
        public void replace() {            
           Dimension d = pan.getPreferredSize();
           pan.setPreferredSize(new Dimension(++width,d.height));     
           pack();
        static void elapsed(String mess) {
            long ct = System.currentTimeMillis();
            System.out.println("Elapsed milliseconds, " + mess + ": " +
                               (ct - tm));
            tm = ct;
    }Running this with Sun jdk 1.3.1 yields the timings:
    Elapsed milliseconds, in constructor: 2226
    Elapsed milliseconds, repack 1: 26
    Elapsed milliseconds, repack 2: 24
    Elapsed milliseconds, repack 2: 25
    Elapsed milliseconds, repack 2: 24Running the same code with jdk 1.4.1_0 yields
    Elapsed milliseconds, in constructor: 1773
    Elapsed milliseconds, repack 1: [bold]5747[/bold]
    Elapsed milliseconds, repack 2: 32
    Elapsed milliseconds, repack 2: 7
    Elapsed milliseconds, repack 2: 1Note the FIVE SECOND delay during the first setPreferredSize()- pack() sequence.
    This problem also occurs with 1.4.0, Blackdown 1.4.1 and IBM 1.4.0, so presumably it is something in Sun's 1.4 code.
    The only way I've found to avoid the initial delay is to set frame invisible
    before the setPreferredSize(), pack() sequence and visible afterwards. But of course this makes the window 'flash' and is very unplesant for users.
    I've looked at the source for pack() but it hasn't gotten me anywhere. If anyone has an idea about fixing this problem or working around it, I'd appreciate hearing about it.
    FYI I ran these tests under Linux, vanilla installations of SuSE 8.0 and 8.1
    Thanks,
    bw

    It turns out that this problem occurs under SuSE (8.0 and 8.1) but NOT under Redhat 8.0
    I do NOT understand how this is possible, but it is the case. Has anyone encountered any SuSE specific problems?
    fyi I've reproduced the problem on two rather different i386 machines (an AMD k7 and a Pentium III thinkpad), so it certainly doesn't have anything to do with hardware.
    bw

  • Intialized a AudioClip In JFrame(help pls)

    alarmSound = getAudioClip(getDocumentBase(),"alarm.au")
    ^
    .\Winpro.java:24: cannot resolve symbol
    symbol : class alarmSound
    location: class Winpro
    alarmSound = getAudioClip(getDocumentBase(),"alarm.au")
    ^
    2 errors
    what the problem for the error above..I wana to initial the audio inside the application(Jframe)
    i use
    AudioClip alarmSound ;
    alarmSound = getAudioClip(getDocumentBase(),"alarm.au");
    It doesnt; seeem to work

    Hi,
    You must learn about the Sound API first...
    JRG

  • Needing help: using Keylistener to change images

    I am trying to using the arrow keys to switch between pictures i have but i cant get it to work... mind that im relativly new at java. Here is what i trying to do:
    starts at pic1: press up: frame now has pic2: press down: frame now shows pic1
    my code so far:
    public class test2 {
    static JFrame frame;
    static int position = 0;
    public static void main(String args[]){
    JFrame.setDefaultLookAndFeelDecorated(true);     
    frame = new JFrame("Frame Title");
    JMenuBar menuBar = new JMenuBar();
    JMenu menuFile = new JMenu("File");
    JMenu menuHelp = new JMenu("Help");
    JMenuItem menuFileExit = new JMenuItem("Exit");
    JMenuItem menuFilePlay = new JMenuItem("New");
    JMenuItem menuFileAbout = new JMenuItem("About");
    JMenuItem menuFileHelp = new JMenuItem("Help");
    menuFile.add(menuFilePlay);
    menuHelp.add(menuFileAbout);
    menuHelp.add(menuFileHelp);
    menuFile.add(menuFileExit);
    menuBar.add(menuFile);
    menuBar.add(menuHelp);
         frame.setJMenuBar(menuBar);
    frame.setSize(1025, 769);
    JLabel temp3 = new JLabel(new ImageIcon("EQ2_000000.gif"));     
    JPanel temp4 = new JPanel();
    temp4.add(temp3);
    frame.getContentPane().add(temp4);
    frame.setVisible(true);
    frame.setIconImage(new ImageIcon("bear.gif").getImage());
    menuFileExit.addActionListener
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    System.exit(0);
    menuFileAbout.addActionListener
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JFrame About = new JFrame("About");
    About.setSize(200, 200);
    About.setIconImage(new ImageIcon("bear.gif").getImage());
                        JLabel temp = new JLabel(new ImageIcon("bear.gif"));     
                        JPanel temp2 = new JPanel();
                        temp2.add(temp);
                        About.setContentPane(temp2);
                        About.setVisible(true);
    menuFileHelp.addActionListener
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    JFrame About = new JFrame("Help");
    About.setSize(200, 200);
    About.setIconImage(new ImageIcon("bearr.gif").getImage());
                        About.setVisible(true);
         frame.addWindowListener
    new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.addKeyListener
    new KeyAdapter() {
    public void keyPressed(KeyEvent ke) {
                        switch (ke.getKeyCode()) {
                   case KeyEvent.VK_LEFT:
                   break;
    case KeyEvent.VK_RIGHT:
    break;
                        case KeyEvent.VK_UP:
                             frame.getContentPane().removeAll();
                             position = position + 1;
                             JLabel temp7 = new JLabel(new ImageIcon("pics/EQ2_00000" + position + ".gif"));     
                        JPanel temp8 = new JPanel();
                        temp8.add(temp7);
                        frame.getContentPane().add(temp8);
                        System.out.print(" u, " + position );
                   break;
    case KeyEvent.VK_DOWN:
         frame.getContentPane().removeAll();
    position = position - 1;
                             JLabel temp5 = new JLabel(new ImageIcon("pics/EQ2_00000" + position + ".gif"));     
                        JPanel temp6 = new JPanel();
                        temp6.add(temp5);
                        frame.getContentPane().add(temp6);
                             System.out.print(" d, " + position);
    }

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class KeyControl
        BufferedImage[] images;
        int imageIndex;
        JLabel label;
        public KeyControl()
            loadImages();
            imageIndex = 0;
            label = new JLabel(new ImageIcon(images[0]));
            //label.requestFocusInWindow();
            registerKeys(label);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
        private void changeImage(int index)
            label.setIcon(new ImageIcon(images[index]));
            label.repaint();
        private Action up = new AbstractAction()
            public void actionPerformed(ActionEvent e)
                imageIndex = (imageIndex - 1) % images.length;
                if(imageIndex < 0)
                    imageIndex = images.length - 1;
                changeImage(imageIndex);
        private Action down = new AbstractAction()
            public void actionPerformed(ActionEvent e)
                imageIndex = (imageIndex + 1) % images.length;
                changeImage(imageIndex);
        private void registerKeys(JComponent c)
            c.getInputMap().put(KeyStroke.getKeyStroke("UP"), "UP");
            c.getActionMap().put("UP", up);
            c.getInputMap().put(KeyStroke.getKeyStroke("DOWN"), "DOWN");
            c.getActionMap().put("DOWN", down);
        private void loadImages()
            String[] fileNames = { "greathornedowl.jpg", "mtngoat.jpg" };
            images = new BufferedImage[fileNames.length];
            for(int j = 0; j < images.length; j++)
                try
                    URL url = getClass().getResource("images/" + fileNames[j]);
                    images[j] = ImageIO.read(url);
                catch(MalformedURLException mue)
                    System.err.println("url: " + mue.getMessage());
                catch(IOException ioe)
                    System.err.println("read: " + ioe.getMessage());
        public static void main(String[]args)
            new KeyControl();
    }

  • Problem In getting output when running JavaHelp System

    Hi I am giving my code from which i want to display my Java Help system......
    Here when i run my program it will give me output as...
    init:
    deps-jar:
    compile:
    run:
    BUILD SUCCESSFUL (total time: 0 seconds)
    But it will nt show any help browser or help system to me........
    can anyone should help me in this.......
    public class HelpSystem extends JFrame implements ActionListener {
        protected static boolean helpOpen= false;
        private static Menu Help;
        private JMenuItem startJavaHelp() {
        JMenuItem mi = null;
        try {
          URL url = new URL("/root/damandeep/HelpDemo1/src/help.hs"); // replace this   with the actual location of your help set
          HelpSet hs = new HelpSet(null, url);
          HelpBroker hb = hs.createHelpBroker();
          mi = new JMenuItem("Contents");
          mi.addActionListener(new CSH.DisplayHelpFromSource(hb));
          hb.setDisplayed(true);
        catch (Exception e) {
          e.printStackTrace();
        return mi;
        private JMenuItem mi;
        /** Creates a new instance of HelpSystem */
        public HelpSystem() {
            setSize(800,600);
             setLocationRelativeTo(null);
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JMenuBar menuBar= new JMenuBar();
             JMenu help= new JMenu("Help");
             //setupHelpFrame();
             help.addMenuListener(new MListener("Help"));
             menuBar.add(help);
        private class MListener implements MenuListener, Runnable
             private String name;
             private JFrame helpFrame;
             public MListener(String nm)
                  name= nm;
             // Invoked when the menu is selected.
             public void menuSelected(MenuEvent me)
                  SwingUtilities.invokeLater(this);
             public void run()
               if (name.equals("Help") & !helpOpen)
                     helpOpen= true;
                    helpFrame= new JFrame("Help");
                     helpFrame.setSize(200,500);
                     helpFrame.setLocationRelativeTo(null);
                     JEditorPane helpContent= new JEditorPane();
                     helpFrame.getContentPane().add(helpContent);
                     helpFrame.setVisible(true);
               else if (name.equals("Help") & helpOpen)
                    helpFrame.toFront();
             // Invoked when the menu is cancelled.
             public void menuCanceled(MenuEvent me)
                helpOpen= false;
                helpFrame.dispose();
             // Invoked when the menu is deselected.
             public void menuDeselected(MenuEvent me)
        public void actionPerformed(ActionEvent e) {
    public static void main(String args[])
    new HelpSystem();
    }Thanks in advance.........

    Plz give me reply as it is very urgent for me.......

  • SpringForm problem!!

    Hi, this is my code:
    class LoginForm {
             private void createAndShowGUI() {
                 String[] labels = {"Username: ", "Password: "};
                 int numPairs = labels.length;
                 //Crea e riempie il pannello
                 JPanel p = new JPanel(new SpringLayout());
                 for (int i = 0; i < numPairs; i++) {
                      JLabel l = new JLabel(labels, JLabel.TRAILING);
         p.add(l);
         JTextField textField = new JTextField(10);
         l.setLabelFor(textField);
         p.add(textField);
    //set graphic
    JFrame.setDefaultLookAndFeelDecorated(true);
    //makes the frame and set it up
    JFrame frame = new JFrame("Login");
    frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    frame.setResizable(false);
    //set the content pane
    p.setOpaque(true);
    frame.setContentPane(p);
    Container contentPane = frame.getContentPane();
    //Lay out the buttons in one row and as many columns
    //as necessary, with 6 pixels of padding all around.
    contentPane.add(new JButton("LOGIN"));
    SpringUtilities.makeCompactGrid(contentPane, contentPane.getComponentCount(),
    1,
    6, 6, 6, 6);
    //Visualizza la finestra
    frame.pack();
    frame.setVisible(true);
    this is actually making a grid with 1 column and 5 rows like this:
    Username:
    [TEXTFIELD ]
    Password:
    [TEXTFIELD ]
    [LOGIN BUTTON]
    how can I make a grid like this:
    Username: [TEXTFIELD ]
    Password: [TEXTFIELD ]
    [     LOGIN BUTTON        ]
    makeCompactGrid is the method from
    http://www-sfb288.math.tu-berlin.de/Documentation/java/tutorial/uiswing/layout/spring.html
    I really need help!!

    first of all thank you!
    I solved the problem using this code:
    private void createAndShowGUI() {
                  setSize(200,150);   
                  setLocation(300,300);   
                  Container frame = getContentPane();   
                  frame.setLayout(new BorderLayout());   
                  JPanel jp[] = new JPanel[9];   
                  for(int i = 0; i < jp.length; i++)    {     
                  if(i < 6) jp[i] = new JPanel(new BorderLayout());     
                  else jp[i] = new JPanel(new FlowLayout());   
                  JLabel ll = new JLabel("Username: ");  
                  JLabel l2 = new JLabel("Password: ");   
                  JTextField tf0 = new JTextField(10);   
                  JTextField tf1 = new JTextField(10);   
                  JButton btn = new JButton("LOGIN");   
                  jp[6].add(ll);   
                  jp[6].add(tf0);   
                  jp[7].add(l2);   
                  jp[7].add(tf1);   
                  jp[2].add(jp[6],BorderLayout.NORTH);   
                  jp[2].add(jp[7],BorderLayout.CENTER);   
                  jp[5].add(btn,BorderLayout.SOUTH);   
                  jp[0].add(jp[2],BorderLayout.NORTH);   
                  jp[1].add(jp[5],BorderLayout.SOUTH);   
                  frame.add(jp[0],BorderLayout.WEST);   
                  frame.add(jp[1],BorderLayout.SOUTH);
                setContentPane(frame);   
                  setVisible(true);
             }now... how can I have the graphic of springlayout in this frame??
    If i invoke this method, which opens a springlayout frame, and then invoke createAndShowGUI() my frame gets the springlayout graphic
    private void HelpGUI() {
                 String[] text = {"login       => effettua la connessione al server Arena", "register  => effettua la registrazione al server Arena"};
                 int numPairs = text.length;
                 //Crea e riempie il pannello
                 JPanel p = new JPanel(new SpringLayout());
                 for (int i = 0; i < numPairs; i++) {
                     JTextField l = new JTextField(text,26);
    l.setEditable(false);
    p.add(l);
    //Layout del pannello
    SpringUtilities.makeCompactGrid(p,
    numPairs, 1, //righe, colonne
    6, 6, //initX, initY
    6, 6); //xPad, yPad
    //Imposta la Grafica carina
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Crea e imposta la finestra
    JFrame frame = new JFrame("Help");
    frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    frame.setResizable(false);
    //Imposta il content pane
    p.setOpaque(true); //rende il content pane opaco
    frame.setContentPane(p);
    //Visualizza la finestra
    frame.pack();
    frame.setVisible(true);

  • Html page does not appear???

    I am designin a hepl page.I've written the code as follows
    but the html does not appear.Instead the panel holding the
    html is plain white.Why is this so?
    P.S: i am able to view the html in a explorer.
    Font demoFont = new Font("Serif", Font.PLAIN, 14);
        quotePane = null;
        scrollPane3 = null;
        s=null;
           try
        { s="file:\\myjava\\HELP.html";
          URL url = new URL(s);
             quotePane = new JEditorPane(url);
             quotePane.setEditable(false);
          scrollPane3 = new JScrollPane(quotePane);
             scrollPane3.setMinimumSize(new Dimension(390,490));
          scrollPane3.setPreferredSize(new Dimension(390,490));
          scrollPane3.setMaximumSize(new Dimension(390,490));
             if (DEBUG)
          { System.out.println(quotePane.getText());
               quotePane.setText(quotePane.getText());
        catch (java.io.IOException e)
        { scrollPane3 = new JScrollPane(new JTextArea("Can't find HTML file."));
             scrollPane3.setFont(demoFont);
        htmlTextPane = new JPanel();
         htmlTextPane.add(scrollPane3);
            /*htmlTextPane.setBorder(BorderFactory.createCompoundBorder(
                          BorderFactory.createTitledBorder("HTML Text"),
                          BorderFactory.createEmptyBorder(0, 5, 5, 5)
        //helppane=new JPanel();
        //htmlTextPane.setBackground(Color.magenta);
        HelpFrame=new JFrame("Help Index");
        HelpFrame.addWindowListener(new WindowAdapter()
                                 public void windowClosing(WindowEvent e)
                                   HelpFrame.setVisible(false);
        HelpFrame.getContentPane().add(htmlTextPane);
        HelpFrame.pack();
        HelpFrame.setSize(400,500);
        Container c=getContentPane();
        c.add(mainpane);

    More info ...
    Can we see the whole program please.

  • Help ! To Lock  The Position Of a JFrame ?!!

    hi..
    How can i lock the Position of a JFrme..
    my requirement is to lock the position of a JFrame.. so that it cannot be dragged on a screen.. but must be resizable... is that possible ?
    any suggestions ??
    Thanking You in advance...
    _rG.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    well sorry..
    i guess you are speaking with respect to windows ..
    well i left out to tell ya..
    i'm working on a macintosh..
    so i need the requirement as per the client to lock its position but not the size...
    the desktop on a macintosh can be viewed else with short keys..
    any help ?!!
    _rG.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help!! How to put more than one JComponent on one JFrame

    Hi!
    I'm having a big problem. I'm trying to create an animation that is composed of various images. In one JComponent I have an animation of a sprite moving left and right on the screen(Which works right now). On another JComponent I have a still image that I want to put somewhere on the screen. For some reason I can only see what I add last to the JFrame. Can somebody help me? Thanks
    P.S I don't want to have all the images on the same JComponent. I want to have different classes for different images or animations. You can get the sprites I use from here http://www.flickr.com/photos/59719950@N00/
    import java.awt.Color;
    import javax.swing.JFrame;
    public class ScreenSaverViewer
         public static void main(String[] args)
         Character characterGame = new Character();
         basketballHoop hoopz = new basketballHoop();
         //Clock clock = new Clock();
         JFrame app = new JFrame("Screensaver");
            app.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            app.getContentPane().add(hoopz);
            //app.getContentPane().add(clock);
            app.getContentPane().add(characterGame);
            app.setSize (450,450);
            app.setBackground (Color.black);
            app.setLocation (300,200);
            app.setVisible (true);
            characterGame.run();
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    import java.util.ArrayList;
    public class Character extends JComponent
        BufferedImage backbuffer;
        int sliderSpeed = 1;
        int sliderX = 1;
        int sliderY = 1;
        int direction = 1;
        Image myImg = Toolkit.getDefaultToolkit().getImage ("/home/climatewarrior/Sprites_gabriel/muneco_0.png");
        private Image fetchImage(int x)
             ArrayList<Image> images = new ArrayList<Image>();
             for (int i = 0; i < 4; i++)
                  images.add(i, Toolkit.getDefaultToolkit().getImage ("/home/climatewarrior/Sprites_gabriel/muneco_" + i + ".png"));
             return images.get(x);
        private void displayGUI()
            int appWidth = getWidth();
            int appHeight = getHeight();
            backbuffer = (BufferedImage) createImage (appWidth, appHeight);
            Graphics2D g2 = backbuffer.createGraphics();
            g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.drawImage (myImg, sliderX, sliderY, getWidth() / 2 * direction, getHeight() / 2, this);
            g2.dispose();
            repaint();
        public void paintComponent (Graphics g)
            super.paintComponent(g);
            if (backbuffer == null)
                 displayGUI();
            g.drawImage(backbuffer, 0, 0, this);
       public void run ()
            while(true)
                   sliderX = -(getWidth() - getWidth()/2);
                   sliderY = getHeight()/3;
                   int x = 0;
                   int increment = 1;
                   do
                   sliderX += increment;
                   if (sliderX % 30 == 0)
                             myImg = fetchImage(x);
                             direction = -1;
                             x++;
                             if (x == 4)
                             x = 0;
                   displayGUI();
                   } while (sliderX <= getWidth() + (getWidth() - getWidth()/2));
                   do
                   sliderX -= increment;
                   if (sliderX % 30 == 0)
                        myImg = fetchImage(x);
                        direction = 1;
                        x++;
                        if (x == 4)
                             x = 0;
                   displayGUI();
                   } while (sliderX >= -(getWidth() - getWidth()/2));
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import javax.swing.*;
    public class Clock extends JComponent
        BufferedImage backbuffer;
        Image myImg = Toolkit.getDefaultToolkit().getImage("/home/climatewarrior/Sprites_gabriel/score_board.png");
        public void paintComponent (Graphics g)
             g.drawImage(myImg, 250, 100, getWidth()/2, getHeight()/3, null);
             super.paintComponent (g);
             repaint();
    }

    Here's a file I had hanging around. It's about as simple as they come, hopefully not too simple!
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    class SimpleAnimationPanel extends JPanel
        private static final int DELAY = 20;
        public static final int X_TRANSLATION = 2;
        public static final int Y_TRANSLATION = 2;
        private static final String DUKE_FILE = "http://java.sun.com/" +
                  "products/plugin/images/duke.wave.med.gif";
        private Point point = new Point(5, 32);
        private BufferedImage duke = null;
        private Timer timer = new Timer(DELAY, new TimerAction());
        public SimpleAnimationPanel()
            try
                // borrow an image from sun.com
                duke = ImageIO.read(new URL(DUKE_FILE));
            catch (MalformedURLException e)
                e.printStackTrace();
            catch (IOException e)
                e.printStackTrace();
            setPreferredSize(new Dimension(600, 400));
            timer.start();
        // do our drawing here in the paintComponent override
        @Override
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            if (duke != null)
                g.drawImage(duke, point.x, point.y, this);
        private class TimerAction implements ActionListener
            public void actionPerformed(ActionEvent e)
                int x = point.x;
                int y = point.y;
                Dimension size = SimpleAnimationPanel.this.getSize();
                if (x > size.width)
                    x = 0;
                else
                    x += X_TRANSLATION;
                if (y > size.height)
                    y = 0;
                else
                    y += Y_TRANSLATION;
                point.setLocation(new Point(x, y)); // update the point
                SimpleAnimationPanel.this.repaint();
        private static void createAndShowUI()
            JFrame frame = new JFrame("SimpleAnimationPanel");
            frame.getContentPane().add(new SimpleAnimationPanel());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }

  • Need help creating a Jframe

    Hi guys, need a little help here in creating a Jframe. Its not something I am knowledgeable at all with and I need this done for my Introductory Java class. I have the other parts of the program finished as best as I can get it. I will post the problem and my code so you guys can look at it and maybe help me out. All help is appreciated
    Problem:
    Congratulations, your fame as a Java programmer is spreading, and you have been hired by Intelecom Group to create a special application. Using multiple classes design an online address book to keep track of the names, addresses, phone numbers, and birthdays of family members, close friends, and certain business associates. Your program should be able to handle a maximum of 500 entries. This program should load the data from a file, called phoneData.txt.
    User Interface: Using JFrame, create a user interface of your design. Remember, unless notified otherwise, ALL input and output will be via this interface.
    Functionality: The program should be able to do the following:
    a) Search for all of the names and phone numbers by first letter of the last name, (this can be displayed using a message box)
    b) Search for a particular person by last name, displaying their phone number, address, and date of birth.
    c) Display the names of people whose birthday's are in a given month.
    d) Search for a person by their phone number, displaying their name, address, and their relationship (ie. Family, Friend, or Associate
    Code:
    package back_end;
    import java.util.*;
    public class Test_backend
    * @param args
    public static void main(String[] args)
    //Relation_type FRIEND;
    // TODO Auto-generated method stub
    Birthday b1 = new Birthday(9,2,1985);
    Birthday b2 = new Birthday(6,21,1985);
    Birthday b3 = new Birthday(1,2,1990);
    Birthday b4 = new Birthday(1,3,1950);
    Person p1 = new Person ("Sloan", "Mergler", "4 vanderbilt drive",
    "516-551-0829", b1, Relation_type.FRIEND );
    Person p2 = new Person ("Taylor", "Bowne", "21 greywood street",
    "516-944-6812", b2, Relation_type.FRIEND);
    // these are random numbers for birthdays
    Person p3 = new Person ("Daniel", "Py", "21 roger drive apt 2",
    "516-944-7530", b3, Relation_type.FAMILY_MEMBER);
    Person p4 = new Person ("Richard", "Py", "21 roger drive apt 1",
    "516-944-7530", b4, Relation_type.FAMILY_MEMBER);
    Address_book a1 = new Address_book();
    a1.add_to_book(p1);
    a1.add_to_book(p2);
    a1.add_to_book(p3);
    a1.add_to_book(p4);
    System.out.println("This is testing search_by_last_initial");
    Vector vt1a = a1.search_by_last_initial("M");
    Test_backend.printOutVector(vt1a);
    System.out.println("Sloan Mergler should be : ");
    Vector vt1b = a1.search_by_last_initial("P");
    Test_backend.printOutVector(vt1b);
    System.out.println("Daniel Py and Richard Py should be :");
    System.out.println("This is testing search_by_last_Name");
    Person lastname1 = a1.search_by_last_name("Mergler");
    System.out.println(lastname1.first_name + " " + lastname1.last_name +
    " should be Sloan Mergler " );
    Person lastname2 = a1.search_by_last_name("Bowne");
    System.out.println(lastname2.first_name + " " + lastname2.last_name +
    "should be Taylor Bowne" );
    System.out.println("This is testing search_by_birth_month");
    Vector vt3a = a1.search_by_birth_month(1);
    Test_backend.printOutVector(vt3a);
    System.out.println("should be Daniel Py and Richard Py");
    Vector vt3b = a1.search_by_birth_month(6);
    Test_backend.printOutVector(vt3b);
    System.out.println("should be Taylor Bowne");
    System.out.println("This is testing search_by_phone_number");
    Person pt4a = a1.search_by_phone_number("516-944-7530");
    System.out.println(pt4a.first_name + " " + pt4a.last_name +
    " should be Daniel Py");
    Person pt4b = a1.search_by_phone_number("516-551-0829");
    System.out.println(pt4b.first_name + " " + pt4b.last_name +
    " should be Sloan Mergler");
    public static void printOutVector(Vector v1)
    for (int x = 0; x < v1.size(); x++)
    Person p1 = (Person) v1.get(x);
    String s1 = p1.first_name +" " + p1.last_name + "";
    System.out.println(s1);
    return;
    package back_end;
    public enum Relation_type
    FAMILY_MEMBER,
    FRIEND,
    BUSINESS_ASSOCIATE
    package back_end;
    public class Person
    String first_name;
    String last_name;
    String address;
    String phoneNumber;
    Birthday birthday;
    Relation_type relation;
    public Person (String first_name, String last_name, String address, String phoneNumber, Birthday birthday, Relation_type relation)
    this.first_name = first_name;
    this.last_name = last_name;
    this.address = address;
    this.phoneNumber = phoneNumber;
    this.birthday = birthday;
    this.relation = relation;
    // default constructor
    public Person (){}
    package back_end;
    public class Birthday
    int birth_month;
    int birth_day;
    int birth_year;
    Birthday(int birth_month, int birth_day, int birth_year)
    this.birth_month = birth_month;
    this.birth_day = birth_day;
    this.birth_year = birth_year;
    package back_end;
    import java.util.*;
    * This class is the addressbook, it is to keep track of all your associates
    public class Address_book
    int MAX_SIZE = 500;
    public ArrayList book;
    // constructor
    public Address_book()
    this.book = new ArrayList(MAX_SIZE);
    // methods
    public void add_to_book(Person newPerson)
    boolean it_worked = this.book.add(newPerson);
    if (it_worked){ return ;}
    else
    throw new RuntimeException ("Too many items in book, it is filled up");
    * Functionality for this class
    * a) Search for all of the names and phone numbers by first letter of
    * last name (this can be displayed in a message box).
    * b) Search for a particular person by last name, displaying their
    * phone number, address, and date of birth.
    * c) Display the names of people whose birthdays are in a given month.
    * d) Search for a person by phone number, displaying their name,
    * address, and their relationship (ie Family, Friend, or Associate).
    * This method shold work for functionality part a
    * Given a string containing one letter, this function will search through
    * this and try to find all occurances of people whose last name start
    * with the given string and return it in a vector
    public Vector search_by_last_initial (final String last_initial)
    // this is for input error checking
    if (last_initial.length() != 1){
    throw new RuntimeException("Input was not supposed to be that long");
    Vector v1 = new Vector();
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.last_name.startsWith(last_initial))
    v1.add( listed_person);
    return v1;
    * this will work for parth b
    * Given a string, it will search for anyone with last name equal
    * to given string and return the first occurance of a person
    * with that last name
    public Person search_by_last_name ( final String last_name)
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.last_name.equalsIgnoreCase(last_name))
    return listed_person;
    return null;
    * This method should work for part c
    * Given the month, given in the form of an int, it will return a list
    * of people whose Birthdays are in that month
    public Vector search_by_birth_month (final int birth_month)
    // this is for input checking
    if (birth_month > 12 || birth_month < 1)
    throw new RuntimeException("That is not a month");
    // main stuff
    Vector v1 = new Vector();
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.birthday.birth_month == birth_month)
    v1.add( listed_person);
    return v1;
    * This method should satisfy part d
    * Given a phone number in the form 'xxx-xxx-xxxx', this function will
    * return the person with that number
    public Person search_by_phone_number (final String pnumber)
    if (pnumber.length() != 12
    || ! is_It_A_PhoneNumber(pnumber)
    throw new RuntimeException("This phone number is not of right form (ex. xxx-xxx-xxxx)");
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.phoneNumber.equalsIgnoreCase(pnumber))
    return listed_person;
    return null;
    // this function uses the regex features of java which i am not so sure about....
    private boolean is_It_A_PhoneNumber(final String possPnum)
    boolean return_value = true;
    String[] sa1 = possPnum.split("-");
    if (sa1[0].length() != 3 ||
    sa1[1].length() != 3 ||
    sa1[2].length() != 4 ){ return_value = false;}
    return return_value;
    Thanks to anyone who can help me out

    Code:
    package back_end;
    import java.util.*;
    public class Test_backend
    * @param args
    public static void main(String[] args)
    //Relation_type FRIEND;
    // TODO Auto-generated method stub
    Birthday b1 = new Birthday(9,2,1985);
    Birthday b2 = new Birthday(6,21,1985);
    Birthday b3 = new Birthday(1,2,1990);
    Birthday b4 = new Birthday(1,3,1950);
    Person p1 = new Person ("Sloan", "Mergler", "4 vanderbilt drive",
    "516-551-0829", b1, Relation_type.FRIEND );
    Person p2 = new Person ("Taylor", "Bowne", "21 greywood street",
    "516-944-6812", b2, Relation_type.FRIEND);
    // these are random numbers for birthdays
    Person p3 = new Person ("Daniel", "Py", "21 roger drive apt 2",
    "516-944-7530", b3, Relation_type.FAMILY_MEMBER);
    Person p4 = new Person ("Richard", "Py", "21 roger drive apt 1",
    "516-944-7530", b4, Relation_type.FAMILY_MEMBER);
    Address_book a1 = new Address_book();
    a1.add_to_book(p1);
    a1.add_to_book(p2);
    a1.add_to_book(p3);
    a1.add_to_book(p4);
    System.out.println("This is testing search_by_last_initial");
    Vector vt1a = a1.search_by_last_initial("M");
    Test_backend.printOutVector(vt1a);
    System.out.println("Sloan Mergler should be : ");
    Vector vt1b = a1.search_by_last_initial("P");
    Test_backend.printOutVector(vt1b);
    System.out.println("Daniel Py and Richard Py should be :");
    System.out.println("This is testing search_by_last_Name");
    Person lastname1 = a1.search_by_last_name("Mergler");
    System.out.println(lastname1.first_name + " " + lastname1.last_name +
    " should be Sloan Mergler " );
    Person lastname2 = a1.search_by_last_name("Bowne");
    System.out.println(lastname2.first_name + " " + lastname2.last_name +
    "should be Taylor Bowne" );
    System.out.println("This is testing search_by_birth_month");
    Vector vt3a = a1.search_by_birth_month(1);
    Test_backend.printOutVector(vt3a);
    System.out.println("should be Daniel Py and Richard Py");
    Vector vt3b = a1.search_by_birth_month(6);
    Test_backend.printOutVector(vt3b);
    System.out.println("should be Taylor Bowne");
    System.out.println("This is testing search_by_phone_number");
    Person pt4a = a1.search_by_phone_number("516-944-7530");
    System.out.println(pt4a.first_name + " " + pt4a.last_name +
    " should be Daniel Py");
    Person pt4b = a1.search_by_phone_number("516-551-0829");
    System.out.println(pt4b.first_name + " " + pt4b.last_name +
    " should be Sloan Mergler");
    public static void printOutVector(Vector v1)
    for (int x = 0; x < v1.size(); x++)
    Person p1 = (Person) v1.get(x);
    String s1 = p1.first_name +" " + p1.last_name + "";
    System.out.println(s1);
    return;
    package back_end;
    public enum Relation_type
    FAMILY_MEMBER,
    FRIEND,
    BUSINESS_ASSOCIATE
    package back_end;
    public class Person
    String first_name;
    String last_name;
    String address;
    String phoneNumber;
    Birthday birthday;
    Relation_type relation;
    public Person (String first_name, String last_name, String address, String phoneNumber, Birthday birthday, Relation_type relation)
    this.first_name = first_name;
    this.last_name = last_name;
    this.address = address;
    this.phoneNumber = phoneNumber;
    this.birthday = birthday;
    this.relation = relation;
    // default constructor
    public Person (){}
    package back_end;
    public class Birthday
    int birth_month;
    int birth_day;
    int birth_year;
    Birthday(int birth_month, int birth_day, int birth_year)
    this.birth_month = birth_month;
    this.birth_day = birth_day;
    this.birth_year = birth_year;
    package back_end;
    import java.util.*;
    * This class is the addressbook, it is to keep track of all your associates
    public class Address_book
    int MAX_SIZE = 500;
    public ArrayList book;
    // constructor
    public Address_book()
    this.book = new ArrayList(MAX_SIZE);
    // methods
    public void add_to_book(Person newPerson)
    boolean it_worked = this.book.add(newPerson);
    if (it_worked){ return ;}
    else
    throw new RuntimeException ("Too many items in book, it is filled up");
    * Functionality for this class
    * a) Search for all of the names and phone numbers by first letter of
    * last name (this can be displayed in a message box).
    * b) Search for a particular person by last name, displaying their
    * phone number, address, and date of birth.
    * c) Display the names of people whose birthdays are in a given month.
    * d) Search for a person by phone number, displaying their name,
    * address, and their relationship (ie Family, Friend, or Associate).
    * This method shold work for functionality part a
    * Given a string containing one letter, this function will search through
    * this and try to find all occurances of people whose last name start
    * with the given string and return it in a vector
    public Vector search_by_last_initial (final String last_initial)
    // this is for input error checking
    if (last_initial.length() != 1){
    throw new RuntimeException("Input was not supposed to be that long");
    Vector v1 = new Vector();
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.last_name.startsWith(last_initial))
    v1.add( listed_person);
    return v1;
    * this will work for parth b
    * Given a string, it will search for anyone with last name equal
    * to given string and return the first occurance of a person
    * with that last name
    public Person search_by_last_name ( final String last_name)
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.last_name.equalsIgnoreCase(last_name))
    return listed_person;
    return null;
    * This method should work for part c
    * Given the month, given in the form of an int, it will return a list
    * of people whose Birthdays are in that month
    public Vector search_by_birth_month (final int birth_month)
    // this is for input checking
    if (birth_month > 12 || birth_month < 1)
    throw new RuntimeException("That is not a month");
    // main stuff
    Vector v1 = new Vector();
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.birthday.birth_month == birth_month)
    v1.add( listed_person);
    return v1;
    * This method should satisfy part d
    * Given a phone number in the form 'xxx-xxx-xxxx', this function will
    * return the person with that number
    public Person search_by_phone_number (final String pnumber)
    if (pnumber.length() != 12
    || ! is_It_A_PhoneNumber(pnumber)
    throw new RuntimeException("This phone number is not of right form (ex. xxx-xxx-xxxx)");
    final int current_size = this.book.size();
    for ( int x = 0; x < current_size; x++)
    final Person listed_person = (Person) this.book.get(x);
    if (listed_person.phoneNumber.equalsIgnoreCase(pnumber))
    return listed_person;
    return null;
    // this function uses the regex features of java which i am not so sure about....
    private boolean is_It_A_PhoneNumber(final String possPnum)
    boolean return_value = true;
    String[] sa1 = possPnum.split("-");
    if (sa1[0].length() != 3 ||
    sa1[1].length() != 3 ||
    sa1[2].length() != 4 ){ return_value = false;}
    return return_value;
    }

  • Help with adding a JPanel with multiple images to a JFrame

    I'm trying to make a program that reads a "maze" and displays a series of graphics depending on the character readed. The input is made from a file and the output must be placed in a JFrame from another class, but i can't get anything displayed. I have tried a lot of things, and i am a bit lost now, so i would thank any help. The input is something like this:
    20
    SXXXXXXXXXXXXXXXXXXX
    XXXX XXXXXXXXXXX
    X XXXXX
    X X XX XXXXXXXXXXXX
    X XXXXXXXXX XXX
    X X XXXXXXXXX XXXXX
    X XXXXX XXXXX XXXXX
    XX XXXXX XX XXXX
    XX XXXXX XXXXXXXX
    XX XX XXXX XXXXXXXX
    XX XX XXXXXXXX
    XX XXX XXXXXXXXXXXXX
    X XXXXXXXXXXXXX
    XX XXXXXXX !
    XX XXXXXX XXXXXXXXX
    XX XXXXXXX XXXXXXXXX
    XX XXXXXXXX
    XX XXXX XXXXXXXXXXXX
    XX XXXX XXXXXXXXXXXX
    XXXXXXXXXXXXXXXXXXXX
    Generated by the Random Maze Generator
    And the code for the "translator" is this:
    package project;
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    public class Translator extends JFrame {
       private FileReader Reader;
       private int size;
       Image wall,blank,exit,start,step1,step2;
      public Translator(){}
      public Translator(File F){
      try {
           Reader=new FileReader(F);}
      catch (IOException e){
           JOptionPane.showMessageDialog(null,"Error Opening File","Error",JOptionPane.ERROR_MESSAGE);}
      try {
      size=Reader.read();
      System.out.write(size);}
      catch (IOException e){
           JOptionPane.showMessageDialog(null,"Error Opening File","Error",JOptionPane.ERROR_MESSAGE);}
      Toolkit theKit=Toolkit.getDefaultToolkit();
      wall=theKit.getImage("wall.gif");
      blank=theKit.getImage("blanktile.jpg");
      exit=theKit.getImage("exit.jpg");
      start=theKit.getImage("start.jpg");
      step1=theKit.getImage("start.jpg");
      step2=theKit.getImage("step1.jpg");
      JPanel panel=new JPanel(){
      public void paintComponent(Graphics g) {
      super.paintComponents(g);
      int ch=0;
      System.out.print("a1 ");
      int currentx=0;
      int currenty=0;
      try {ch=Reader.read();
          System.out.write(ch);}
      catch (IOException e){}
      System.out.print("b1 ");
      while(ch!=-1){
        try {ch=Reader.read();}
        catch (IOException e){}
        System.out.write(ch);
        switch (ch){
            case '\n':{currenty++;
                      break;}
            case 'X':{System.out.print(">x<");
                     g.drawImage(wall,(currentx++)*20,currenty*20,this);
                     break;}
           case ' ':{
                     g.drawImage(blank,(currentx++)*20,currenty*20,this);
                     break;}
            case '!':{
                     g.drawImage(exit,(currentx++)*20,currenty*20,this);
                      break;}
            case 'S':{
                     g.drawImage(start,(currentx++)*20,currenty*20,this);
                      break;}
            case '-':{
                     g.drawImage(step1,(currentx++)*20,currenty*20,this);
                      break;}
            case 'o':{
                      g.drawImage(step2,(currentx++)*20,currenty*20,this);
                      break;}
            case 'G':{ch=-1;
                      break;}
                  }//Swith
          }//While
      }//paintComponent
    };//Panel
    panel.setOpaque(true);
    setContentPane(panel);
    }//Constructor
    }//Classforget all those systems.out and that stuff, that is just for the testing
    i call it in another class in this way:
    public Maze(){
        firstFrame=new JFrame("Random Maze Generator");
        firstFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        (...)//more constructor code here
        Translator T=new Translator(savefile);
        firstFrame.add(T);
        firstFrame.getContentPane().add(c);
        firstFrame.setBounds(d.width/3,d.height/3,d.width/2,d.height/4);
        firstFrame.setVisible(true);
        c.setSize(d.width/2,d.height/4);
        c.show();
        }i know it may be a very basic or concept problem, but i can't get it solved
    thanks for any help

    Try this. It's trivial to convert it to use your images.
    If you insist on storing the maze in a file, just read one line at a
    time into an ArrayList than convert to an array and pass that to the
    MazePanel constructor.
    Any questions, just ask.
    import java.awt.*;
    import javax.swing.*;
    public class CFreman1
         static class MazePanel
              extends JPanel
              private final static int DIM= 20;
              private String[] mMaze;
              public MazePanel(String[] maze) { mMaze= maze; }
              public Dimension getPreferredSize() {
                   return new Dimension(mMaze[0].length()*DIM, mMaze.length*DIM);
              public void paint(Graphics g)
                   g.setColor(Color.BLACK);
                   g.fillRect(0, 0, getSize().width, getSize().height);
                   for (int y= 0; y< mMaze.length; y++) {
                        String row= mMaze[y];
                        for (int  x= 0; x< row.length(); x++) {
                             Color color= null;
                             switch (row.charAt(x)) {
                                  case 'S':
                                       color= Color.YELLOW;
                                       break;
                                  case 'X':
                                       color= Color.BLUE;
                                       break;
                                  case '!':
                                       color= Color.RED;
                                       break;
                             if (color != null) {
                                  g.setColor(color);
                                  g.fillOval(x*DIM, y*DIM, DIM, DIM);
         public static void main(String[] argv)
              String[] maze= {
                   "SXXXXXXXXXXXXXXXXXXX",
                   "    XXXX XXXXXXXXXXX",
                   "X              XXXXX",
                   "X  X XX XXXXXXXXXXXX",
                   "X    XXXXXXXXX   XXX",
                   "X  X XXXXXXXXX XXXXX",
                   "X  XXXXX XXXXX XXXXX",
                   "XX XXXXX XX     XXXX",
                   "XX XXXXX    XXXXXXXX",
                   "XX  XX XXXX XXXXXXXX",
                   "XX  XX      XXXXXXXX",
                   "XX XXX XXXXXXXXXXXXX",
                   "X      XXXXXXXXXXXXX",
                   "XX XXXXXXX         !",
                   "XX  XXXXXX XXXXXXXXX",
                   "XX XXXXXXX XXXXXXXXX",
                   "XX          XXXXXXXX",
                   "XX XXXX XXXXXXXXXXXX",
                   "XX XXXX XXXXXXXXXXXX",
                   "XXXXXXXXXXXXXXXXXXXX"
              JFrame frame= new JFrame("CFreman1");
              frame.getContentPane().add(new MazePanel(maze));
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setResizable(false);
              frame.setVisible(true);
    }

  • Help needed in refreshing a panel in  a JFrame.

    I have some problem in refreshing a panel of a window.
    Here I am writting the sample code bellow.
    My program contains 2 classes, one is "Test" other is "Testwindow".
    class Test contains main(),displays the buttons reading from the string array obtained by listing a directory in my local file system through the panel p2 .If I click "Add" button in Test, class Testwindow's constructor is called & "Testwindow" is visible, which has a textfield. If you enter a string in the textfield, that string will be stored as a file in the same directory that the 1st window use. here I choose "C:\\temp" of my filesystem as the directory.
    My requirement is:
    when I enter a string in the textfield of Testwindow, then after clicking "Finish" button, that inputted string should be added to the panel p2 of 1st window(Test)during runtime.It means the panel p2 should be refreshed reading from the "C:\\temp" as soon as a new button is added to temp directory during runtime.
    If any of you have idea over this,please help sending me the updated version of the code given below.
    Regards.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class Test extends JFrame
    JPanel p1,p2;
    JButton b1,bdir[];
    File f;
    String s[];
    int n,nmax;
    public Test()
    super("Test");
    JPanel con=(JPanel)getContentPane();
    con.setLayout(new BorderLayout());
    addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e)
    System.exit(0);
    p1=new JPanel();
    p2=new JPanel();
    p2.setLayout(new GridLayout(nmax,1));
    b1=new JButton("Add");
    b1.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand()=="Add")
    new Testwindow();
    p1.add(b1);
    f=new File("c:\\temp");
    s=f.list();
    n=s.length;
    nmax=n+20;
    bdir=new JButton[n];
    for(int i=0; i<n; i++)
    bdir=new JButton(s);
    bdir.setHorizontalAlignment(AbstractButton.LEADING);
    p2.add(bdir);
    int hor=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int ver=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp=new JScrollPane(p2,hor,ver);
    con.add(p1,"North");
    con.add(jsp,"Center");
    setSize(250,300);
    public static void main(String arg[])
    Test frame=new Test();
    frame.setVisible(true);
    class Testwindow extends JFrame implements ActionListener
    JPanel p1,p2,p3;
    JLabel l1;
    JTextField tf1;
    JButton b1,b2;
    String s1, sdir[];
    public Testwindow()
    setTitle("Testwindow");
    Container con=getContentPane();
    con.setLayout(new BorderLayout());
    p1=new JPanel();
    p1.setLayout(new GridLayout(1,2));
    p2=new JPanel();
    l1=new JLabel("Enter a string: ");
    tf1=new JTextField();
    b1=new JButton("Finish");
    b1.addActionListener(this);
    p1.add(l1);
    p1.add(tf1);
    p2.add(b1);
    con.add(p1,"North");
    con.add(p2, "South");
    setSize(300,150);
    show();
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand()=="Finish"){
    try{
    s1=tf1.getText();
    File id_name=new File("C:\\temp\\"+s1+".txt");
    FileOutputStream out=new FileOutputStream(id_name);
    out.close();
    catch(IOException x)
    System.out.println("Exception caught"+x);
    this.setVisible(false);

    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    public class test extends JFrame {
      JPanel p1, p2;
      JButton b1, bdir[];
      File f;
      String[] s;
      int n, nmax;
      public test() {
        super("Test");
        p1 = new JPanel();
        p2 = new JPanel();
        p2.setLayout(new GridLayout(nmax ,1));
        b1 = new JButton("Add");
        b1.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            new Testwindow(test.this);
        p1.add(b1);
        f = new File("c:\\temp");
        s = f.list();
        n = s.length;
        nmax = n + 20;
        bdir = new JButton[n];
        for(int j = 0; j < n; j++) {
          bdir[j] = new JButton(s[j]);
          bdir[j].setHorizontalAlignment(AbstractButton.LEADING);
          p2.add(bdir[j]);
        JScrollPane jsp = new JScrollPane(p2);
        getContentPane().add(p1, "North");
        getContentPane().add(jsp, "Center");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(250,300);
        setLocation(100,100);
        setVisible(true);
       * Called by actionPerformed method in Testwindow
      public void addButton(String title) {
        JButton button = new JButton(title);
        button.setHorizontalAlignment(AbstractButton.LEADING);
        p2.add(button);
        p2.revalidate();
      public static void main(String[] args) {
        new test();
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    class Testwindow extends JFrame implements ActionListener {
      JPanel p1,p2,p3;
      JLabel label1;
      JTextField tf1;
      JButton b1,b2;
      String s1, sdir[];
      test client;
      public Testwindow(test client) {
        setTitle("Testwindow");
        this.client = client;
        p1=new JPanel();
        p1.setLayout(new GridLayout(1,2));
        p2=new JPanel();
        label1=new JLabel("Enter a string: ");
        tf1=new JTextField();
        b1=new JButton("Finish");
        b1.addActionListener(this);
        p1.add(label1);
        p1.add(tf1);
        p2.add(b1);
        getContentPane().add(p1, "North");
        getContentPane().add(p2, "South");
        setSize(300,150);
        setLocation(360,100);
        setVisible(true);
      public void actionPerformed(ActionEvent e) {
        JButton button = (JButton)e.getSource();
        if(button == b1) {
          try {
            s1=tf1.getText();
            File id_name=new File("C:\\temp\\"+s1+".txt");
            FileOutputStream out=new FileOutputStream(id_name);
            out.close();
          catch(IOException x) {
            System.out.println("Exception caught"+x);
          s1 = tf1.getText();
          client.addButton(s1);
          this.setVisible(false);
    }

  • JFrame Problem!!! pls help

    Hi everyone,
    I'm using JFrame in my GUI desing and I try to insert JTable in it with using JPanel. Here is the code for the problem portion:
                    k = new JTable( );
                    gbcPanel0.gridx = 3;
                    gbcPanel0.gridy = GridBagConstraints.RELATIVE;
                    gbcPanel0.gridwidth = 100;
                    gbcPanel0.gridheight = 100;
                    gbcPanel0.fill = GridBagConstraints.BOTH;
                    //gbcPanel0.weightx = 1;
                    gbcPanel0.weighty = 5;
                    gbcPanel0.anchor = GridBagConstraints.NORTH;
                    gbPanel0.setConstraints( k, gbcPanel0 );When this section appears on the screen with my actionlistener button, it always appear at the right most part of the screen. But I would like to see it at the bottom of screen as a new paragraph (sorry for simile). I have read somewhere; in JFrame addings will be appear at the right most default.
    I would be glad if you help me to change this

              getContentPane().setLayout(new GridBagLayout());
              JPanel firstParagraph = new JPanel();
              JTable secondParagraph = createTable();
              GridBagConstraints gbc = new GridBagConstraints();
              gbc.gridx = 0;
              gbc.gridy = 0;
              gbc.fill = GridBagConstraints.BOTH;
              gbc.weightx = 1;
              gbc.weighty = 1;
              gbc.anchor = GridBagConstraints.NORTH;
              getContentPane().add(firstParagraph, gbc);
              gbc.gridy++;
              getContentPane().add(new JScrollPane(secondParagraph), gbc);

  • Jframe is flickering -- Urgent help please!

    Basically i want to resize the window when i click some button say, NEW or EDIT and making some components visible.
    I am using setSize() method to resize the Jframe/window and setVisible() method.
    Do i need to use other methods. If you need some other details let me know as soon as possible.
    Below is the code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.awt.Insets;
    import java.awt.GridBagLayout;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import com.symantec.itools.javax.swing.borders.LineBorder;
    import com.symantec.itools.javax.swing.borders.EtchedBorder;
    import com.symantec.itools.javax.swing.borders.BevelBorder;
    import com.symantec.itools.javax.swing.borders.CompoundBorder;
    import com.symantec.itools.javax.swing.borders.EmptyBorder;
    public class psRulesEditQ extends JFrame implements WindowListener
    public boolean inDebugMode = false;
    DBClient mydb;
    String SchemaID;
    int flagQ;
    int flagA;     
    DefaultListModel QuestionsModel = new DefaultListModel();
    DefaultListModel AnswersModel = new DefaultListModel();
    YesNoDialog alert;
    public psRulesEditQ (String title, DBClient mydb, String SchemaID)
    super(title);
    this.mydb = mydb;
    this.SchemaID = SchemaID;
    init();
    getQuestions();
    setTitle("Edit Questions for Domain: " + UserAttributes.getCurrentDomainName());
         public void init()
              // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
              //symantec.itools.lang.Context.setApplet(this);
              // This line prevents the "Swing: checked access to system event queue" message seen in some browsers.
              getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
              // This code is automatically generated by Visual Cafe when you add
              // components to the visual environment. It instantiates and initializes
              // the components. To modify the code, only use code syntax that matches
              // what Visual Cafe can generate, or Visual Cafe may be unable to back
              // parse your Java file into its visual environment.
              //{{INIT_CONTROLS
              getContentPane().setLayout(null);
              setSize(660,330);
              //setBounds(50,50,660,330);
              EditQuestionsPanel.setLayout(null);
              getContentPane().add(EditQuestionsPanel);
              EditQuestionsPanel.setBounds(0,0,660,520);
              QuestionsPane.setOpaque(true);
              EditQuestionsPanel.add(QuestionsPane);
              QuestionsPane.setBounds(12,48,396,144);
              QuestionsPane.getViewport().add(QuestionsList);
              QuestionsList.setBounds(0,0,393,141);
              AnswersPane.setOpaque(true);
              EditQuestionsPanel.add(AnswersPane);
              AnswersPane.setBounds(444,48,192,144);
              AnswersPane.getViewport().add(AnswersList);
              AnswersList.setBounds(0,0,189,141);
              EditQuestionsPane.setOpaque(true);
              EditQuestionsPanel.add(EditQuestionsPane);
              EditQuestionsPane.setBounds(12,324,360,120);
              EditQuestionsPane.setVisible(false);
              EditQuestionsPane.getViewport().add(EditQuestionsTextArea);
              EditQuestionsTextArea.setBounds(0,0,357,117);
              EditQuestionsPanel.add(EditAnswersTextField);
              EditAnswersTextField.setBounds(444,324,134,25);
              EditAnswersTextField.setVisible(false);
              DeleteQuestionButton.setText("Delete");
              DeleteQuestionButton.setActionCommand("Delete");
              EditQuestionsPanel.add(DeleteQuestionButton);
              DeleteQuestionButton.setBounds(12,204,70,24);
              EditQuestionButton.setText("Edit");
              EditQuestionButton.setActionCommand("Edit");
              EditQuestionsPanel.add(EditQuestionButton);
              EditQuestionButton.setBounds(96,204,70,24);
              NewQuestionButton.setText("New");
              NewQuestionButton.setActionCommand("New");
              EditQuestionsPanel.add(NewQuestionButton);
              NewQuestionButton.setBounds(180,204,70,24);
              DeleteAnswerButton.setText("Delete");
              DeleteAnswerButton.setActionCommand("Delete");
              EditQuestionsPanel.add(DeleteAnswerButton);
              DeleteAnswerButton.setBounds(444,204,70,24);
              EditAnswerButton.setText("Edit");
              EditAnswerButton.setActionCommand("Edit");
              EditQuestionsPanel.add(EditAnswerButton);
              EditAnswerButton.setBounds(515,204,60,24);
              NewAnswerButton.setText("New");
              NewAnswerButton.setActionCommand("New");
              EditQuestionsPanel.add(NewAnswerButton);
              NewAnswerButton.setBounds(576,204,60,24);
              OkButton.setText("Ok");
              OkButton.setActionCommand("Ok");
              EditQuestionsPanel.add(OkButton);
              OkButton.setBounds(12,456,60,24);
              OkButton.setVisible(false);
              OkButton1.setText("Ok");
              OkButton1.setActionCommand("Ok");
              EditQuestionsPanel.add(OkButton1);
              OkButton1.setBounds(444,360,60,24);
              OkButton1.setVisible(false);
              CancelButton.setText("Cancel");
              CancelButton.setActionCommand("Cancel");
              EditQuestionsPanel.add(CancelButton);
              CancelButton.setBounds(84,456,73,24);
              CancelButton.setVisible(false);
              CancelButton1.setText("Cancel");
              CancelButton1.setActionCommand("Cancel");
              EditQuestionsPanel.add(CancelButton1);
              CancelButton1.setBounds(504,360,73,24);
              CancelButton1.setVisible(false);
              ShowRulesButton.setText("Show Rules");
              ShowRulesButton.setActionCommand("Show Rules");
              EditQuestionsPanel.add(ShowRulesButton);
              ShowRulesButton.setBounds(444,240,108,24);
              CloseButton.setText("Close");
              CloseButton.setActionCommand("Close");
              EditQuestionsPanel.add(CloseButton);
              CloseButton.setBounds(564,240,72,24);
              QuestionsLabel.setText("Questions");
              EditQuestionsPanel.add(QuestionsLabel);
              QuestionsLabel.setBounds(12,18,72,24);
              AnswersLabel.setText("Answers");
              EditQuestionsPanel.add(AnswersLabel);
              AnswersLabel.setBounds(444,12,60,36);
              EditQuestionsLabel.setText("Edit Questions");
              EditQuestionsPanel.add(EditQuestionsLabel);
              EditQuestionsLabel.setBackground(new java.awt.Color(204,204,204));
              EditQuestionsLabel.setBounds(12,276,90,48);
              EditQuestionsLabel.setVisible(false);
              NewQuestionsLabel.setText("New Questions");
              EditQuestionsPanel.add(NewQuestionsLabel);
              NewQuestionsLabel.setBounds(12,276,90,48);
              NewQuestionsLabel.setVisible(false);
              NewAnswersLabel.setText("New Answers");
              EditQuestionsPanel.add(NewAnswersLabel);
              NewAnswersLabel.setBounds(444,276,80,48);
              NewAnswersLabel.setVisible(false);
              EditAnswersLabel.setText("Edit Answers");
              EditQuestionsPanel.add(EditAnswersLabel);
              EditAnswersLabel.setBounds(444,276,80,48);
              EditAnswersLabel.setVisible(false);
              BorderLabel1.setBorder(etchedBorder1);
              EditQuestionsPanel.add(BorderLabel1);
              BorderLabel1.setBounds(5,12,643,264);
              BorderLabel2.setBorder(etchedBorder2);
              EditQuestionsPanel.add(BorderLabel2);
              BorderLabel2.setBounds(5,274,643,216);
              BorderLabel2.setVisible(false);
              //$$ etchedBorder1.move(0,540);
              //$$ etchedBorder2.move(24,540);
         QuestionsList.setModel(QuestionsModel);
         AnswersList.setModel(AnswersModel);
    //add all the listeners
    LAction LAction1 = new LAction();
         LSelector LSelector1 = new LSelector();
         //buttons
    CloseButton.addActionListener(LAction1);
    OkButton.addActionListener(LAction1);
    OkButton1.addActionListener(LAction1);
    DeleteAnswerButton.addActionListener(LAction1);
    DeleteQuestionButton.addActionListener(LAction1);
    NewAnswerButton.addActionListener(LAction1);
    NewQuestionButton.addActionListener(LAction1);
         EditQuestionButton.addActionListener(LAction1);
         EditAnswerButton.addActionListener(LAction1);
         CancelButton.addActionListener(LAction1);
         CancelButton1.addActionListener(LAction1);
    //ShowRulesButton.addActionListener(LAction1);
    //lists
         QuestionsList.addListSelectionListener(LSelector1);
         AnswersList.addListSelectionListener(LSelector1);
    //window
    this.addWindowListener(this);
         //{{DECLARE_CONTROLS
         javax.swing.JPanel EditQuestionsPanel = new javax.swing.JPanel();
         javax.swing.JScrollPane QuestionsPane = new javax.swing.JScrollPane();
         javax.swing.JList QuestionsList = new javax.swing.JList();
         javax.swing.JScrollPane AnswersPane = new javax.swing.JScrollPane();
         javax.swing.JList AnswersList = new javax.swing.JList();
         javax.swing.JScrollPane EditQuestionsPane = new javax.swing.JScrollPane();
         javax.swing.JTextArea EditQuestionsTextArea = new javax.swing.JTextArea();
         javax.swing.JTextField EditAnswersTextField = new javax.swing.JTextField();
         javax.swing.JButton DeleteQuestionButton = new javax.swing.JButton();
         javax.swing.JButton EditQuestionButton = new javax.swing.JButton();
         javax.swing.JButton NewQuestionButton = new javax.swing.JButton();
         javax.swing.JButton DeleteAnswerButton = new javax.swing.JButton();
         javax.swing.JButton EditAnswerButton = new javax.swing.JButton();
         javax.swing.JButton NewAnswerButton = new javax.swing.JButton();
         javax.swing.JButton OkButton = new javax.swing.JButton();
         javax.swing.JButton OkButton1 = new javax.swing.JButton();
         javax.swing.JButton CancelButton = new javax.swing.JButton();
         javax.swing.JButton CancelButton1 = new javax.swing.JButton();
         javax.swing.JButton ShowRulesButton = new javax.swing.JButton();
         javax.swing.JButton CloseButton = new javax.swing.JButton();
         javax.swing.JLabel QuestionsLabel = new javax.swing.JLabel();
         javax.swing.JLabel AnswersLabel = new javax.swing.JLabel();
         javax.swing.JLabel EditQuestionsLabel = new javax.swing.JLabel();
         javax.swing.JLabel NewQuestionsLabel = new javax.swing.JLabel();
         javax.swing.JLabel NewAnswersLabel = new javax.swing.JLabel();
         javax.swing.JLabel EditAnswersLabel = new javax.swing.JLabel();
         javax.swing.JLabel BorderLabel1 = new javax.swing.JLabel();
         javax.swing.JLabel BorderLabel2 = new javax.swing.JLabel();
         javax.swing.JOptionPane JOptionPane1 = new javax.swing.JOptionPane();
         javax.swing.JOptionPane JOptionPane2 = new javax.swing.JOptionPane();
         javax.swing.JOptionPane JOptionPane3 = new javax.swing.JOptionPane();
         javax.swing.JOptionPane JOptionPane4 = new javax.swing.JOptionPane();
         javax.swing.JOptionPane JOptionPane5 = new javax.swing.JOptionPane();
         javax.swing.JOptionPane JOptionPane6 = new javax.swing.JOptionPane();
         javax.swing.JOptionPane JOptionPane7 = new javax.swing.JOptionPane();
         com.symantec.itools.javax.swing.borders.EtchedBorder etchedBorder1 = new com.symantec.itools.javax.swing.borders.EtchedBorder();
         com.symantec.itools.javax.swing.borders.EtchedBorder etchedBorder2 = new com.symantec.itools.javax.swing.borders.EtchedBorder();
    public void getQuestionInfo()
    String SQL, line, QuestionID, info="";
    QuestionID = parseID(QuestionsList.getSelectedValue().toString());
    SQL = "SELECT Additional FROM ps_questions WHERE QuestionID = " + QuestionID;
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    info = mydb.getColumn(0);
    line = mydb.getRow();
    YesNoDialog d = new YesNoDialog(this, "Additional Information for Question " + QuestionID, info, "OK", null, null);
    if (d.getAnswer() == d.YES)
    d.dispose();
    public void getAnswerInfo()
    String SQL, line, AnswerID, info="";
    AnswerID = parseID(AnswersList.getSelectedValue().toString());
    SQL = "SELECT Additional FROM ps_answers WHERE AnswerID = " + AnswerID;
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    info = mydb.getColumn(0);
    line = mydb.getRow();
    YesNoDialog d = new YesNoDialog(this, "Additional Information for Answer " + AnswerID, info, "OK", null, null);
    if (d.getAnswer() == d.YES)
    d.dispose();
    public void getQuestions()
    String SQL, line;
    SQL = "SELECT QuestionID, QuestionText FROM tps_questions WHERE SchemaID = " + SchemaID + " ORDER BY QuestionID ASC";
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    QuestionsModel.addElement("Q" + mydb.getColumn(0) + ": " + mydb.getColumn(1));
    line = mydb.getRow();
    public String parseID(String str)
    return str.substring(1, str.indexOf(":"));
    public void getAnswers()
    String SQL, line, QuestionID;
    String Question = QuestionsList.getSelectedValue().toString();
    AnswersModel.removeAllElements();
    QuestionID = parseID(Question);
    SQL = "SELECT AnswerID, AnswerText FROM tps_answers WHERE QuestionID = " + QuestionID;
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    AnswersModel.addElement("A" + mydb.getColumn(0) + ": " + mydb.getColumn(1));
    line = mydb.getRow();
    public void setQuestion()
         EditAnswersTextField.setText("");
    String q = QuestionsList.getSelectedValue().toString();
    EditQuestionsTextArea.setText(q.substring(q.indexOf(":")+2, q.length()));
    public void setAnswer()
    String q = AnswersList.getSelectedValue().toString();
    EditAnswersTextField.setText(q.substring(q.indexOf(":")+2, q.length()));
    public String getNewID(String tableName, String fieldName)
    String SQL, line, newID;
    SQL = "";
    if (tableName.equals("tps_answers"))
    SQL = "SELECT MAX(AnswerID) FROM " + tableName;
    else if (tableName.equals("tps_questions"))
    SQL = "SELECT MAX(QuestionID) FROM " + tableName;
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    int n = Integer.parseInt(mydb.getColumn(0).trim());
    n++;
    newID = n + "";
    return newID;
    public void addNewQuestion()
    //add to db and list
    int index;
    String q, QuestionID;
    q = EditQuestionsTextArea.getText();
    QuestionID = getNewID("tps_questions", "QuestionID");
    if (!(q.substring(q.length()-1, q.length())).equals("?"))
    q = q + "?";
    QuestionsModel.addElement("Q" + QuestionID + ": " + q);
    mydb.addRow("tps_questions");
    mydb.setColumn("QuestionID", QuestionID);
    mydb.setColumn("SchemaID", SchemaID);
    mydb.setColumn("QuestionText", "'" + q + "'");
    mydb.setColumn("Additional", "'null'");
    mydb.update();
         EditQuestionsTextArea.setText("");
         AnswersModel.removeAllElements();
         index = QuestionsModel.getSize();
         QuestionsList.setSelectedIndex(index-1);
    public void addEditQuestion()
         int i = QuestionsModel.indexOf(QuestionsList.getSelectedValue());
         String QuestionID = parseID(QuestionsList.getSelectedValue().toString());
         String q = EditQuestionsTextArea.getText();
              if (!(q.substring(q.length()-1, q.length())).equals("?"))
    q = q + "?";
         QuestionsModel.set(i, "Q" + QuestionID + ": " + q);
         mydb.editRow("tps_questions","QuestionID = " + QuestionID);
         mydb.setColumn("QuestionID", QuestionID);
    mydb.setColumn("SchemaID", SchemaID);
    mydb.setColumn("QuestionText", "'" + q + "'");
    mydb.setColumn("Additional", "'null'");
    mydb.update();
    public void addEditAnswer()
         String a, AnswerID, QuestionID;
    String q = QuestionsList.getSelectedValue().toString();
    a = EditAnswersTextField.getText();
    if (inDebugMode) System.err.println("a = " + a);
    QuestionID = parseID(q);
         int i = AnswersModel.indexOf(AnswersList.getSelectedValue());
    AnswerID = parseID(AnswersList.getSelectedValue().toString());
    AnswersModel.set(i, "A" + AnswerID + ": " + a);
    mydb.editRow("tps_answers","AnswerID = " + AnswerID);
    mydb.setColumn("QuestionID", QuestionID);
    mydb.setColumn("AnswerID", AnswerID);
    mydb.setColumn("SchemaId", SchemaID);
    mydb.setColumn("AnswerText", "'" + a + "'");
    mydb.setColumn("Additional", "'null'");
    mydb.update();
    // EditAnswersTextField.setText("");
    public void addNewAnswer()
    //getItems() method in List
    String a, AnswerID, QuestionID;
    String q = QuestionsList.getSelectedValue().toString();
    a = EditAnswersTextField.getText();
    if (inDebugMode) System.err.println("a = " + a);
    QuestionID = parseID(q);
    AnswerID = getNewID("tps_answers", "AnswerID");
    mydb.addRow("tps_answers");
    mydb.setColumn("QuestionID", QuestionID);
    mydb.setColumn("AnswerID", AnswerID);
    mydb.setColumn("SchemaId", SchemaID);
    mydb.setColumn("AnswerText", "'" + a + "'");
    mydb.setColumn("Additional", "'null'");
    mydb.update();
    AnswersModel.addElement("A" + AnswerID + ": " + a);
    EditAnswersTextField.setText("");
    //added 9-2-97 lmc - deletes an answer
    public void deleteAnswer(String answer)
    String msg;
    //getRulesA(answer);
    String Answer = AnswersList.getSelectedValue().toString();
    String AnswerID = answer.substring(1, answer.indexOf(":"));
    msg = "Are you sure you want to delete the answer:\n";
    msg += " \n";
    msg += AnswersList.getSelectedValue().toString() + " \n";
    msg += " \nThe following rules also use this question as a precondition.\n";
    //for (int i=0; i<rules.getLastVisibleIndex(); i++)
    // rules.setSelectedIndex(i);
    // msg += " \n rule " + rules.getSelectedIndex();
    msg += " \n \nDeleting the answer will affect these rules.";
    YesNoDialog confirm = new YesNoDialog(this, "Delete Answer " + AnswerID, msg, "Delete", "Cancel", null);
    if (confirm.getAnswer() == confirm.YES)
    mydb.deleteRow("tps_answers", "AnswerID=" + AnswerID);
    mydb.deleteRow("tps_preconditions", "AnswerID=" + AnswerID);
    AnswersModel.removeElementAt(AnswersList.getSelectedIndex());
    else System.err.println("did not delete");
    public void deleteQuestion(String question)
    String msg, SQL, line;
    String QuestionID = question.substring(1, question.indexOf(":"));
    //getRulesQ(question);
    msg = "Are you sure you want to delete the question:\n";
    msg += " \n";
    msg += QuestionsList.getSelectedValue().toString() + " \n";
    msg += " \nThe following rules also use this question as a precondition.\n";
    //for (int i=0; i<rules.getLastVisibleIndex(); i++)
    // rules.setSelectedIndex(i);
    // msg += " \n rule " + rules.getSelectedIndex();
    msg += " \n \nDeleting the question will affect these rules.";
    YesNoDialog confirm = new YesNoDialog(this, "Delete Question " + QuestionID, msg, "Delete", "Cancel", null);
    if (confirm.getAnswer() == confirm.YES)
    mydb.deleteRow("tps_questions", "QuestionID=" + QuestionID);
    SQL = "SELECT QuestionID FROM tps_answers WHERE QuestionID=" + QuestionID;
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    mydb.deleteRow("tps_answers", "QuestionID=" + QuestionID);
    line = mydb.getRow();
    QuestionsModel.removeElementAt(QuestionsList.getSelectedIndex());
    AnswersModel.removeAllElements();
         EditQuestionsTextArea.setText("");          
    else System.err.println("did not delete");
    public void showRules(String question)
    ListFrame allRules;
    String QuestionID = question.substring(1, question.indexOf(":"));
    allRules = new ListFrame("All the Rules that Contain Question " + QuestionID, "Q", question, rules);
    allRules.show();
    /* //added 2/18/01 srh to make the "Show Rules" button work
    public void showRules(String question, String answer)
    ListFrame allRules;
    java.awt.List matchingRules = new java.awt.List();
    String listId, type="", SQL, line;
    if (question != null)
    {  listId = question.substring(1, question.indexOf(":"));
    type = "Quesiton";
    else if (answer != null)
    {  listId = answer.substring(1, question.indexOf(":"));
    type = "Answer";
    else
    {  //AppletGlobals.eval("alert('You must choose a quesiton or answer to display.')");
    alert = new YesNoDialog(this, "Add Answer ...", "You must choose a quesiton or answer to display.", "OK", null, null);
    return;
    SQL = "SELECT RuleID FROM tps_preconditions WHERE PreQuestionId = "+ listId;
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    matchingRules.add(mydb.getColumn(0));
    line = mydb.getRow();
    allRules = new ListFrame("All the Rules that Contain "+type+" " + listId, "P", question, matchingRules);
    allRules.show();
    public void getRulesQ(String question)
    String SQL, line;
    String QuestionID;
         rules = new javax.swing.Jlist();
    QuestionID = question.substring(1, question.indexOf(":"));
    SQL = "SELECT RuleID FROM tps_preconditions WHERE PreQuestionID=" + QuestionID;
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    rules.add(mydb.getColumn(0));
    line = mydb.getRow();
    public void getRulesA(String answer)
    String SQL, line;
    String AnswerID;
    rules = new javax.swing.Jlist();
    AnswerID = answer.substring(1, answer.indexOf(":"));
    SQL = "SELECT RuleID FROM tps_preconditions WHERE AnswerID=" + AnswerID;
    mydb.closeSQL();
    mydb.sendSQL(SQL);
    line = mydb.getRow();
    while (mydb.more())
    rules.add(mydb.getColumn(0));
    line = mydb.getRow();
         //ActionListener method
         class LAction implements java.awt.event.ActionListener
    public void actionPerformed(java.awt.event.ActionEvent event)
         Object object = event.getSource();
              if (object == CloseButton)
              dispose();
              else if (object == NewQuestionButton)
                        flagQ = 0;
                        setSize(660,550);
                        psRulesEditQ.this.setVisible(true);
                        //QuestionsList.setEnabled(false);
                        EditQuestionsLabel.setVisible(false);
                        NewAnswersLabel.setVisible(false);
                        EditAnswersLabel.setVisible(false);
                        EditAnswersTextField.setVisible(false);
              OkButton1.setVisible(false);
                        CancelButton1.setVisible(false);
                        BorderLabel2.setVisible(true);
                        CancelButton.setVisible(true);
                        NewQuestionsLabel.setVisible(true);
                        EditQuestionsPane.setVisible(true);
              EditQuestionsTextArea.setText("");
                        OkButton.setVisible(true);
                        //setSize(670,551);
                        //psRulesEditQ.this.getContentPane().setSize(670,551);
                        //EditQuestionsPane.repaint();
              else if (object == NewAnswerButton)
                        flagA = 0;
                        EditAnswersLabel.setVisible(false);          
                        NewQuestionsLabel.setVisible(false);
                        EditQuestionsLabel.setVisible(false);
                        EditQuestionsPane.setVisible(false);
                        OkButton.setVisible(false);
                        CancelButton.setVisible(false);
                             if (QuestionsList.isSelectionEmpty())
                             JOptionPane5.showMessageDialog(psRulesEditQ.this, "Select the question first!","Message",JOptionPane.PLAIN_MESSAGE);
                             else
                             setSize(660,550);
                             psRulesEditQ.this.setVisible(true);
                             BorderLabel2.setVisible(true);
                             //QuestionsList.setEnabled(true);
                             NewAnswersLabel.setVisible(true);
                             EditAnswersTextField.setVisible(true);
                   EditAnswersTextField.setText("");
                             OkButton1.setVisible(true);
                             CancelButton1.setVisible(true);
                   else if (object == EditQuestionButton)
                        flagQ = 1;
                        //QuestionsList.setEnabled(true);
                        NewQuestionsLabel.setVisible(false);
                        NewAnswersLabel.setVisible(false);
                        EditAnswersLabel.setVisible(false);
                        EditAnswersTextField.setVisible(false);
              OkButton1.setVisible(false);
                        CancelButton1.setVisible(false);
                        EditQuestionsLabel.setVisible(true);
                             if (QuestionsList.isSelectionEmpty())
                             JOptionPane2.showMessageDialog(psRulesEditQ.this, "Select a question to edit!","Message",JOptionPane.PLAIN_MESSAGE);
                             else
                             setSize(660,550);
                             psRulesEditQ.this.setVisible(true);
                             BorderLabel2.setVisible(true);
                             EditQuestionsPane.setVisible(true);     
                             OkButton.setVisible(true);
                             CancelButton.setVisible(true);
                             setQuestion();
                   else if (object == EditAnswerButton)
                        flagA = 1;
                        NewQuestionsLabel.setVisible(false);
                        NewAnswersLabel.setVisible(false);
                        EditQuestionsLabel.setVisible(false);
                        EditQuestionsPane.setVisible(false);
                        OkButton.setVisible(false);
                        CancelButton.setVisible(false);
                        EditAnswersLabel.setVisible(true);
                             if (AnswersList.isSelectionEmpty())
                             JOptionPane3.showMessageDialog(psRulesEditQ.this, "Select an answer to edit!","Message",JOptionPane.PLAIN_MESSAGE);
                             else
                             setSize(660,550);
                             psRulesEditQ.this.setVisible(true);
                             BorderLabel2.setVisible(true);
                             EditAnswersTextField.setVisible(true);
                             OkButton1.setVisible(true);
                             CancelButton1.setVisible(true);
                             setAnswer();
              else if (object == OkButton)
                   if (flagQ == 0)
                                  String x = EditQuestionsTextArea.getText();
                                  if (x.equals(""))
                                  JOptionPane6.showMessageDialog(psRulesEditQ.this, "You must type in a question first!","Message",JOptionPane.PLAIN_MESSAGE);
                                  else
                                  addNewQuestion();
                                  QuestionsList.setEnabled(true);
                             else if (flagQ == 1)
                             addEditQuestion();
                             setSize(660,330);
                             BorderLabel2.setVisible(false);
                             NewQuestionsLabel.setVisible(false);
                             EditQuestionsLabel.setVisible(false);
                             EditQuestionsPane.setVisible(false);
                             OkButton.setVisible(false);
                             CancelButton.setVisible(false);
              else if (object == OkButton1)
                             if (flagA == 0)
                                  String y = EditAnswersTextField.getText();
                                  if (y.equals(""))
                                  JOptionPane7.showMessageDialog(psRulesEditQ.this, "You must type in an answer first!","Message",JOptionPane.PLAIN_MESSAGE);
                                  else
                                  addNewAnswer();     
                             else if (flagA == 1)
                             addEditAnswer();
                             setSize(660,330);
                             BorderLabel2.setVisible(false);
                             NewAnswersLabel.setVisible(false);
                             EditAnswersLabel.setVisible(false);
                             EditAnswersTextField.setVisible(false);
                   OkButton1.setVisible(false);
                             CancelButton1.setVisible(false);
              else if (object == DeleteQuestionButton)
                             if (QuestionsList.isSelectionEmpty())
                             JOptionPane1.showMessageDialog(psRulesEditQ.this, "Select a question to delete!","Message",JOptionPane.PLAIN_MESSAGE);
              BorderLabel2.setVisible(false);
                        NewQuestionsLabel.setVisible(false);
                        EditQuestionsLabel.setVisible(false);
                        EditQuestionsPane.setVisible(false);
                        OkButton.setVisible(false);
                        CancelButton.setVisible(false);
                        CancelButton1.setVisible(false);
                        NewAnswersLabel.setVisible(false);
                        EditAnswersLabel.setVisible(false);
                        EditAnswersTextField.setVisible(false);
              OkButton1.setVisible(false);
                        deleteQuestion(QuestionsList.getSelectedValue().toString());
              else if (object == DeleteAnswerButton)
                   if (AnswersList.isSelectionEmpty())
                             JOptionPane4.showMessageDialog(psRulesEditQ.this, "Select an answer to delete!","Message",JOptionPane.PLAIN_MESSAGE);
                        BorderLabel2.setVisible(false);
                        NewQuestionsLabel.setVisible(false);
              EditQuestionsLabel.setVisible(false);
                        EditQuestionsPane.setVisible(false);
                        OkButton.setVisible(false);
                        CancelButton.setVisible(false);
                        CancelButton1.setVisible(false);
                        NewAnswersLabel.setVisible(false);
                        EditAnswersLabel.setVisible(false);
                        EditAnswersTextField.setVisi

    Hi,
    I have a JApplet with JComponents. When the size of the JApplet is larger than the browser, scrollbar of the browser is used. Flickering is very worse when scrolled. Any help in this regard is appreciated.
    Kiru

Maybe you are looking for

  • 7373 and contact image

    Hi I have some serious problems adding contact pictures with my new 7373 phone. It keeps telling me "operation failed" after I press the save button at the end of the process... It dosn't matter in which way I approach. I can go through the contact l

  • KDE4 "When lid closed" event problem

    Hi, i'm using updated Arch Linux system with KDE4. My problem is, that KDE Power Manager does not hear on lid close event. I can choose everything from menu (suspend, lock screen, ...) but it does nothing. After closing the lid, system follows "Do no

  • Iphone 4 with tmobile cannot receive mms

    I have a factory unlocked iphone 4 on tmobile, i was unable to recieve mms, but then I input this: APN: epc.tmobile.com mmsc:hhtp://mms.msg.eng.t-mobile.com/mms/wapenc mms proxy: 216.155.165.50:8080 mms max message size: 1048576 mms ua prof URL: http

  • Lost free space after an "Erase Free Space" procedure

    I just ran the "Erase Free Space" application from the Dick Utility. The erase failed and now I have ZERO free space available. I am now showing that all 111g or used oposed to roughly 50% prior to the Erase Free Space. I have found a few articles tr

  • Selected an item in a combobox with the keypad

    Hello, i am working on a flex project. In my form, I have 3 combo box to handle the birthdate. But I can't use my keypad to choose the date or the year. Do you know how to resolve it ? Thank you