Validate/repaint applet

Hi,
I've got a problem with repaint for a japplet
what i do is removing a jscrollpane to replace it by another one. so i remove the first component and i add a second !
the problem is that, on the screen, the first one disappears but when i add the second, nothing is visible !!!
I've tried everything : invalidate,validate,repaint (on the container, on the parent,...)
the only thing to see the second one is resizing the browser !!!
have you a solution ???
Thanks
Greg

getContentPane().remove(panelName);
getContentPane().add("Center",panelName); // assumes BorderLayout
validate();

Similar Messages

  • Problem repainting applet

    Hello (first, sorry for my English),
    I have a JApplet that contains a component that extends a JPanel. That component contains a button and a (self-done) progress bar that extends a Canvas.
    The % of completing is variable, but applet doesn't refresh correctly. Only I can watch the 0% and 100%, all the intermediate values are lost.
    I use repaint() after a new %, but it doesn't works :(
    Help me please!!!
    Thanks!

    I would suggest you place your applet to servlet communication in a separate thread. Then have your paint method check to see if this thread is finished, otherwise sleep for a bit, and call repaint()?

  • Help with repainting applet using TreeControl Component

    Does someone know how I could force my TreeControl to repaint
    itself when an action occurs. Currently when I expand a node
    I can only see the results after I minimize the screen and bring
    it back. The applet runs fine in JDeveloper.
    Cheers,
    Sunil
    null

    Sunil,
    For the tree control, use the available event handlers (see the
    Property Inspector) and call a repaint method for each of the
    events that you want to cause a refresh.
    -L.
    Sunil (guest) wrote:
    : Does someone know how I could force my TreeControl to repaint
    : itself when an action occurs. Currently when I expand a node
    : I can only see the results after I minimize the screen and
    bring
    : it back. The applet runs fine in JDeveloper.
    : Cheers,
    : Sunil
    null

  • Repaint applet

    Hi!
    I have a problem repainting my JApplet (BorderLayout) as the browser window is maximized or minimized. The scrollbars of a small window remains when maximizing the browser. Any ideas?

    I found this reply on a similar problem...
    In your html, capture the 'onresize' event of the browser. In onresize, you can use the capability that javascript can communicate with an applet. Call the repaint method of your applet from javascript trigger by onresize.
    Check out this link:
    http://java.sun.com/products/plugin/1.3/docs/jsobject.html

  • Jframe blues ( another validate, repaint question )

    i can use validate() or repaint() just fine when i use it via a JButton or a JOptionPane.
    but when i use it via an event ( any event ) it doesnt work.
    the background changes to the background color but no components are showing
    when i click over where they're supposed to be they suddenly appear....
    even better, i use an option in my jmenu that pops a JOptionPane, click on the ok button and
    suddenly, all the components of me jframe suddenly appear!
    well, can somebody tell me what to do after
    frame.validate();
    so that all the components shows?
    thx
    PoPo

    ok all is well .....
    resolved the problem by starting a new thread
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    // insert the code that updates the UI here.
    });

  • Revalidate/validate + repaint to add a number of JTextFields

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class FIFO_MenuBar extends JMenuBar {
    String[] prgsItems = new String[] {"Start Simulation", "Reset", "Exit"};
    String[] typeItems = new String[] {"FCFS", "HRRN", "PR", "RR", "SJF", "SRTN"};
    public JTextField jTxF0[];
    int k = 0;
    public FIFO_MenuBar () {
    JMenu progress = new JMenu("Program to...");
    JMenu typemenu = new JMenu("Simulations Types");
    ActionListener listen = new ActionListener() {
    public void actionPerformed(ActionEvent event) {
    if (event.getActionCommand() == "Start Simulation") {
    k = Integer.parseInt(JOptionPane.showInputDialog("Enter number of process"));
    jTxF0 = new JTextField[k];
    JPanel panel = new JPanel();
    for (int i = 0; i < jTxF0.length; i++) {
    jTxF0[i] = new JTextField(10);
    panel.add(jTxF0);
    for (int i = 0; i < prgsItems.length; i++) {
    JMenuItem item = new JMenuItem(prgsItems[i]);
    item.addActionListener(listen);
    //System.out.println(item.getActionCommand());
    progress.add(item);
    progress.insertSeparator(2);
    for (int j = 0; j < typeItems.length; j++) {
    JMenuItem item = new JMenuItem(typeItems[j]);
    item.addActionListener(listen);
    typemenu.add(item);
    typemenu.insertSeparator(1);
    typemenu.insertSeparator(5);
    JMenuItem item;
    add(progress);
    add(typemenu);
    public static void main(String s[]) {
    JFrame frame = new JFrame("CPU Simulation");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(new FIFO_MenuBar());
    frame.pack();
    frame.setVisible(true);
    No idea why it wouldn't create the number of JTextFields that I want when I go from "Program to..." --> "Start Simulatioin"...
    It just wouldn't add the JTextField for me...

    you generally don't want anything in main() except to kick off the program
    FIFO_MenuBar is a menuBar, so you don't want to be putting your frame code in there,
    best to just pass any needed references.
    here's your code split into 2 classes with the necessary reference passed to FIFO....
    see if you can follow what's happening
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class FIFO_MenuBar extends JMenuBar {
      String[] prgsItems = new String[] {"Start Simulation", "Reset", "Exit"};
      String[] typeItems = new String[] {"FCFS", "HRRN", "PR", "RR", "SJF", "SRTN"};
      public JTextField jTxF0[];
      int k = 0;
      public FIFO_MenuBar (final JPanel panel) {
        JMenu progress = new JMenu("Program to...");
        JMenu typemenu = new JMenu("Simulations Types");
        ActionListener listen = new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            if (event.getActionCommand() == "Start Simulation") {
              k = Integer.parseInt(JOptionPane.showInputDialog("Enter number of process"));
              jTxF0 = new JTextField[k];
              //JPanel panel = new JPanel();
              for (int i = 0; i < jTxF0.length; i++) {
                jTxF0[i] = new JTextField(10);
                panel.add(jTxF0);
    panel.revalidate();
    panel.repaint();
    for (int i = 0; i < prgsItems.length; i++) {
    JMenuItem item = new JMenuItem(prgsItems[i]);
    item.addActionListener(listen);
    //System.out.println(item.getActionCommand());
    progress.add(item);
    progress.insertSeparator(2);
    for (int j = 0; j < typeItems.length; j++) {
    JMenuItem item = new JMenuItem(typeItems[j]);
    item.addActionListener(listen);
    typemenu.add(item);
    typemenu.insertSeparator(1);
    typemenu.insertSeparator(5);
    JMenuItem item;
    add(progress);
    add(typemenu);
    class GUI
    public void buildGUI()
    JPanel framePanel = new JPanel();
    framePanel.setPreferredSize(new Dimension(400,300));
    JFrame frame = new JFrame("CPU Simulation");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(framePanel);
    frame.setJMenuBar(new FIFO_MenuBar(framePanel));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    public static void main(String s[])
    SwingUtilities.invokeLater(new Runnable(){
    public void run(){
    new GUI().buildGUI();

  • Loading Images into Applets

    I've been having problems loading an image into an Applet. I've found that when the getImage() call is put into the init() method it loads the image fine, also implementing an imageUpdate call. However, now I'm trying to expand on this by putting it into a button click, it hangs indefinitely while waiting for the image to load.
    Another interesting point I've noticed is that the Canvas subclass ImageSegmentSelector uses a PixelGrabber in its constructor to put the Image into a buffer - when this class is created from the imageUpdate() call, NOT the init() call, the grabPixels() call hangs indefinitely too!!
    Any feedback, please,
    Jonathan Pendrous
    import java.applet.*;
    import java.net.*;
    import jmpendrous.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    public class XplaneGlobalSceneryDownloader extends Applet implements ActionListener{
    ImageSegmentSelector worldMap;
    Image img;
    URL url;
    int longtitude = 36;
    int latitude = 18;
    boolean imageLoaded;
    TextField t1, t2,t3;
    Label l1,l2,l3;
    Button b1;
    Applet a1;
    public void init() {
    a1 = this;
    l1 = (Label) add(new Label("Number of horizontal sections: "));
    t1 = (TextField) add(new TextField("45",3));
    l2 = (Label) add(new Label("Number of vertical sections: "));
    t2 = (TextField) add(new TextField("45",3));
    l3 = (Label) add(new Label("URL of image file: "));
    t3 = (TextField) add(new TextField("file:///C:/java/work/xplane_project/source/world-landuse.GIF",60));
    b1 = (Button) add(new Button("Load image"));
    b1.addActionListener(this);
    validate();
    // THIS CODE WORKS FINE ...
    /*try { url = new URL("file:///C:/java/work/xplane_project/source/world-landuse.GIF"); }
    catch(MalformedURLException e) { System.exit(0);   }
    img = getImage(url);
    //int w=img.getWidth(this);
    while(imageLoaded==false) { try { Thread.sleep(1000);   } catch(InterruptedException e) {System.exit(0);    } }
    worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
    add(worldMap);
    //resize(worldMap.getWidth(), worldMap.getHeight());
    validate();*/
    //repaint();
    //worldMap = new ImageSegmentSelector(this, img, longtitude, latitude);
    //repaint();
    public void actionPerformed(ActionEvent e) {
    try { longtitude = Integer.parseInt(t1.getText()); } catch (NumberFormatException ex) {System.exit(0); }
    try { latitude = Integer.parseInt(t2.getText()); } catch (NumberFormatException e2) {System.exit(0); }
    try { url = new URL(t3.getText()); }
    catch(MalformedURLException e3) { System.exit(0);   }
    img = getImage(url);
    //int w=img.getWidth(this);
    while(imageLoaded==false)
    { try { Thread.sleep(1000);   } //KEEPS ON LOOPING
    catch(InterruptedException e4) {System.exit(0);    } }
    worldMap = new ImageSegmentSelector(a1, img, longtitude, latitude);
    add(worldMap);
    //resize(worldMap.getWidth(), worldMap.getHeight());
    validate();
    public boolean imageUpdate(Image i, int flags, int x, int y, int w, int h){
    // THIS NEVER GETS CALLED AT ALL //
    if (((flags & ImageObserver.WIDTH) != 0) && ((flags & ImageObserver.HEIGHT) != 0)) {
    //worldMap = new ImageSegmentSelector(this, i, longtitude, latitude);
    //add(worldMap);
    //validate();
    //repaint();
    imageLoaded = true;
    return false;
    return true;
    }

    Sorry, thought this had been lost.
    You can load a file if the applet itself is run from the local filesystem - it loads it fine from the init(), but not otherwise. But I haven't got the applet to run from a browser yet without crashing (it's OK in the IDE debugger), so that's the next step.

  • Applet is caching

    I have a JSP which loads an applet. This JSP contains some parameters which get set depending on who you are logged in as.
    When the applet loads, it reads in these parameters and displays certain things dependant upon those parameters.
    When I log in a userA, the applet loads correctly. When I log out and log back in as userB, it still uses the information from userA. The JSP has changed, and shows different parameter values( the parameters for userB). So it is definitely the applet and not the JSP that is causing the problem.
    So, how do I clear out the applet so it loads the appropriate parameters (in this case, userB)?
    Below is some sample code of what I'm doing.
    public final class MyApplet extends JApplet
       public void start()
          System.out.println( "start" );
       public void init()
          System.out.println( "init" );
          // Set parameters coming in from the HTML file
          try
             // MyProperties is a static class which holds the parameters that get set below
             MyProperties.setServerName( getParameter( "serverName" ) );
             MyProperties.setUserID( getParameter( "userID" ) );
          catch ( Exception e )
             e.printStackTrace();
          // Execute a job on the event-dispatching thread:
          // creating this applet's GUI.
          try
             javax.swing.SwingUtilities.invokeAndWait( new Runnable()
                public void run()
                   //Create gui, etc... in here;
          catch ( Exception e )
             System.err.println( "<ERROR>:  " + e.toString() );
        * Executes after a page reload or when the browser closes.
       public void stop()
          System.out.println( "stop" );
          MyProperties.removeProperties(); // Set all properties to an empty string
          removeAll();
          validate();
          repaint();
    }

    anyway, it shouldn't affect users. the jar files aren't specific to a user. Maybe the page has user data in it? Then you need the no-cache HTTP headers sent with the page the applet is in.

  • Interesting - this repaint() is killing me.

    I am using the repaint() to repaint a couple of JPEG images on an applet,
    its repaints the new images, only when I minimize the window then
    maximize it. abracadabra here it is.
    Is there some sort of refresh(); that would do this for me, I guess I could
    tell the users please minimize then maximize to get the full effect.

    Quite often I've found that you must call these 3 methods on c omponent to insure it gets painted when you want it painted:
    invalidate();
    validate();
    repaint();
    See if this helps.

  • Fully filling of applet in frame.

    Hi I want to fill a frame fully with the applet embedded in it.
    1.Applet code
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JApplet;
    import javax.swing.JPanel;
    import netscape.javascript.JSObject;
    public class TestApplet extends JApplet {
         private static final long serialVersionUID = 1L;
         JPanel jp;
         int width=0;
         int height=0;
         Dimension d;
         Graphics g;
         Image offscreen;
         JSObject js;
         @Override
         public void init() {
              System.out.println("TestApplet.init()");
              js=JSObject.getWindow(this);
              System.out.println("TestApplet.init() after js creation");
              jp=new JPanel();
              jp.setPreferredSize(new Dimension(600,200));
              jp.setBackground(Color.green);
              add(jp);
         @Override
         public void paint(Graphics g) {
              // TODO Auto-generated method stub
              super.paint(g);
         @Override
         public void update(Graphics g) {
              // TODO Auto-generated method stub
              paint(g);
         @Override
         public void setSize(int width, int height) {
              repaint();
              this.width=width;
              this.height=height;     
              System.out.println("TestApplet.setSize()MMMMMMMMMMM width="+width+"height=="+height+"isDoubleBuffered()="+isDoubleBuffered());
              //validate();
    repaint();
    2. Main frame
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <frameset cols="30%,70%" border=3 frameborder=0 framespacing=0>
    <frame src="1.html" border=3 frameborder=0 framespacing=0 />
    <frame src="2.html" border=3 frameborder=0 framespacing=0/>
    </frameset>
    </html>
    3.1st frame
    <html>
    <head>
    <SCRIPT type="text/javascript">
    function debug(s)
         alert(s)
    function resize() {
                   var w_newWidth,w_newHeight;
                   var w_maxWidth=1600,w_maxHeight=1200;
                   if (navigator.appName.indexOf("Microsoft") != -1)
                        w_newWidth=document.body.clientWidth;
                        w_newHeight=document.body.clientHeight;
                   }else{
                        var netscapeScrollWidth=15;
                        w_newWidth=window.innerWidth-netscapeScrollWidth;
                        w_newHeight=window.innerHeight-netscapeScrollWidth;
                   if (w_newWidth>w_maxWidth)
                        w_newWidth=w_maxWidth;
                   if (w_newHeight>w_maxHeight)
                        w_newHeight=w_maxHeight;
    document.myApplet.width=w_newWidth;
    document.myApplet.height=w_newHeight;
                   document.myApplet.setSize(w_newWidth,w_newHeight);
                   document.myApplet.width =w_newWidth;
                   document.myApplet.height = w_newHeight;
                   window.scrollTo(0,0);
              window.onResize = resize;
              window.onLoad = resize;
    </SCRIPT>
    </head>
    <body>
    <applet name="myApplet" code="TestApplet.class" width="100%" height="100%"></applet>
    </body>
    </html>
    Any body has any idea pla share ne ASAP.
    Thank in advance
    rakesh

    am not sure i fully understand the scenario presented
    however, depending on the browser, javascript version supported and permissions it is possible to communicate between frames (ie one html page containing an applet and another html code using js)
    a way could be to create a java object (with static variables, methods) and pass data, as events occur, between the frames (using a combination of java and javascript)
    should be able to quickly test this capability before any indepth coding

  • Applet.getImage() but so sloooooowly...

    I've seen a couple of questions posted about this issue, but no resolution. Essentially, performance of Applet().getImage() is unacceptably slow. It happens on my machine, and others.
    I'm using PlugIn 1.3.1 in WinIE 5.5, and have the following simple JApplet:
    public class GoofyApplet extends JApplet
    public void init()
    Image img = getImage(getDocumentBase(), "goofy/mickey/rtb_down.jpg"); // a 4K .jpg
    JLabel lab = new JLabel("test", new ImageIcon(img), JLabel.CENTER);
    Container content = getContentPane();
    content.add(lab);
    validate();
    repaint();
    I run that, and have ample time to curse and fume. About 20-50 seconds.
    Note the docs for getImage:
    "This method always returns immediately, whether or not the image exists. When this applet attempts to draw the image on the screen, the data will be loaded. The graphics primitives that draw the image will incrementally paint on the screen."
    First of all, timing tests have shown that this definition of "immediately" is pretty flexible. In my last test, getImage took 38230 ms.
    I've been cruising around the Forums, looking for an answer to this question and have yet to find it. This is disturbing--I can't believe SUN would ship the plug-in with this kind of behavior--but does this mean there is no solution?
    Cheers,
    Jon

    You need to wait for the image to load in an applet. If you use the Swing version of ImageIcon it will do this automatically for you. Else, use the following methods:
    * Loads an image as a resource.
    * Note:  With Swing, could use ImageIcon instead of createImage()/MediaTracker.
    public Image loadImage(String imageName) {
       Image image = null;
       URL url = getClass().getResource(imageName);
       try {
          image = createImage((ImageProducer) url.getContent());
          if (image==null) throw new Exception();
          waitForImageToLoad(this,image);
       } catch (Exception e) {
          System.out.println("unable to load image: "+imageName);
       }//end try
       return image;
    }//end loadImage
    * wait for an image to completely load. Use in an applet.
    public static void waitForImageToLoad(Component component, Image image) {
       MediaTracker tracker = new MediaTracker(component);
       try {
          tracker.addImage(image, 0);
          tracker.waitForID(0);
       } catch (InterruptedException e) {
          //this should not occur
          e.printStackTrace();
       }//end try
    }//end waitForImageToLoad

  • Sending vales to another applet

    I checked out that messaging tutorial. The reciever and sender pregrams. What i can't figure out is how to send a value over that connection.

    If its inter-applet communication you want, then here is an example a cooked up with inter-applet, inter-browser window communication:
    /* Applet1 source */
    import javax.swing.*;
    public class Applet1 extends JApplet
      public static Applet1 selfRef = null;
      private javax.swing.JLabel label;
      public void init()
        selfRef = this;
        label = new javax.swing.JLabel();
        getContentPane().add(label);
        createText("Original Label");
      public void createText(String labelStr) {
        label.setText(labelStr);
        validate();
        repaint();
    /* Applet2 source */
    import javax.swing.*;
    public class Applet2 extends JApplet
      Applet1 theOtherApplet = null;
      public void init()
        callApplet1();
      public void callApplet1() {
        theOtherApplet = Applet1.selfRef;
        theOtherApplet.createText("New Label");
    }Make both applets with same code base. When 2nd applet loads in another browser window it will change text of 1st applet.

  • Container's validate does not update removal

    the validate() method does not update the display to show the remval of a component from a container. A way to go around: use repaint() instead.
    Please see the following code:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.JToolBar;
    import net.effortech.harry.swing.Laf;
    public class ScrollPaneViewPort extends JFrame {
      private JButton add = new JButton("Add");
      private JButton remove = new JButton("Remove");
      private JTextField field;
      private JScrollPane scrollPane;
      private ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          JButton s = (JButton) e.getSource();
          if (s == add) {
            add.setEnabled(false);
            remove.setEnabled(true);
            field = new JTextField();
            scrollPane = new JScrollPane(field,
                JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
            getContentPane().add(scrollPane, BorderLayout.SOUTH);
            validate();
          } else {
            add.setEnabled(true);
            remove.setEnabled(false);
            getContentPane().remove(scrollPane);
            validate();
            //repaint();
      public ScrollPaneViewPort() {
        super("ScrollPane ViewPort");
        JToolBar tb = new JToolBar();
        tb.add(add);
        remove.setEnabled(false);
        tb.add(remove);
        add.addActionListener(al);
        remove.addActionListener(al);
        getContentPane().add(tb, BorderLayout.NORTH);
        setBounds(100, 100, 500, 400);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
      public static void main(String[] args) {
        new ScrollPaneViewPort();
    }

    use repaint() insteadThat matches our experiences.

  • How to remove buttons in an applet?

    how can I remove buttons from an applet?

    with the remove method, i guess. don't forget to (in)validate the applet afterwards

  • Hi there, need help for this program...thx!

    Hi there guys,
    I have created this applet program that requires a user to login with a user no, and a password. I am using arrays as to store the defined variables,(as required by my project supervisor). My problem here is that when the arrays are declared in class validateUser(), the program would run fine, but i cant login and i get a NullPointerException error. if the arrays are located in actionPerformed, i get a 'cannot resolve symbol' error for the method 'get' and 'if (Admin.equals(admins.get(i).toString())) ' as well as 'if (Password.equals(passwordsget(i).toString())) '. I am not very effecient in java, hence the untidy program (and i have to admit, it isnt any good), so sorry for any inconvenience caused. Once agani thx in advance ;)
    here are my codings :
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.URL;
    import java.net.*;
    import javax.swing.*;
    import java.lang.*;
    import java.util.Vector;
    public class eg31662 extends Applet implements ActionListener
         Panel panel1, panel2, panel3, panel4, panel5;
         Button login, enter;
         Label inst, top, admin, pass, fieldlabel;
    TextField adminF, passF, field;
    String Admin, Password;
    Vector admins, passwords;
         Thread thread = null;
         boolean status = false;
              public class validateUser extends Applet
                   String[] admins = {"User1", "User2", "User3"};
                   String[] passwords = {"P1", "P2", "P2"};
         public void init()
              setLayout (new BorderLayout());
              panel1 = new Panel(new FlowLayout());
              panel2 = new Panel(new FlowLayout());
              //login button
              login = new Button("Login");
              //instruction
              inst = new Label("Please type in your User no. and the given password in order to proceed");
              //label
              top = new Label("Login login");
              admin = new Label("Admin No :");
              pass = new Label("Password :");
              //input textfields
              adminF = new TextField(8);
              passF = new TextField(10);
              passF.setEchoChar('*');
              panel1.setBackground(Color.gray);
              panel2.setBackground(Color.orange);
              panel2.add(admin);
              panel2.add(adminF);
              panel2.add(pass);
              panel2.add(passF);
              panel2.add(login);
              panel2.add(inst);
              panel1.add(top);
              add(panel1, BorderLayout.NORTH);
              add(panel2, BorderLayout.CENTER);
              login.addActionListener(this);
              setSize(500,400);
         void mainpage()
              boolean flag = true;
              setLayout (new BorderLayout());
              panel1 = new Panel(new FlowLayout());
              panel2 = new Panel(new FlowLayout());
              top = new Label("Welcome");
              enter = new Button("Enter");
              panel2.setBackground(Color.orange);
              panel1.setBackground(Color.gray);
              fieldlabel = new Label("Type something here :");
              field = new TextField(20);
              add(panel1, BorderLayout.NORTH);
              add(panel2, BorderLayout.CENTER);
              panel2.add(fieldlabel);
              panel2.add(field);
              enter.addActionListener(this);
         public void start() {
              if(thread == null) {
                   status = true;
         public void stop() {
              status = false;
         public void run() {
              while(status == true) {
                   try {
                        thread.sleep(50);
                   catch(InterruptedException ie) {
                   repaint();
              thread = null;
         public void actionPerformed(ActionEvent ev)
                   //String[] admins = {"User1", "User2", "User3"};
                   //String[] passwords = {"P1", "P2", "P3"};
              if(ev.getSource() == login)
                   Admin = adminF.getText();
                   Password = passF.getText();
              boolean ok = true;
              for (int i = 0; i < admins.size(); i++) {
              if (Admin.equals(admins.get(i).toString())) {
              if (Password.equals(passwords.get(i).toString())) {
              ok = true;
              this.setVisible(false);
              //break;
                             JOptionPane.showMessageDialog(null, "Welcome, u have successfully logged in");
                             mainpage();
              else {
              ok = false;
              else {
              ok = false;
              if (ok == false) {
                             JOptionPane.showMessageDialog(null,
                        "Incorrect Password or Admin No, Please Try Again",
                        "Access Denied",
                        JOptionPane.ERROR_MESSAGE);
              else {
              this.setVisible(false);
    }

    Hi, sorry to bring this thread up again, but this is actually a continuation from my previous posted program. Hope u guys can help me again!
    Right now i'm supposed to come up with a simple quiz program, which consists of the center panel displayin the question (in a pic format), and a textfield to enter the answer at the lower panel. this goes on for a couple of pages and once it is completed, the final page would display the total correct answers out of the number of questions, as well as the score in percentage form.
    The few(or many) problems taht i'm facing are :
    1)How do i save the answers that are typed in each textfieldAnd later on checked for the correct answer based on the array given?
    2)How do i go about doing the final score in percentage form and total of correct answers?
    3)I previously tried out using canvas, but it didnt seem to work. my questions(pictures) that are supposed to displayed in the center(canvas) produce nothing. How do i rectify that?
    i'm really sorry for the mess in the codings, hope this wouldnt be a hassle for any of u out there. Once again thanks in advance!
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.URL;
    import java.net.*;
    import java.util.Vector;
    import javax.swing.*;
    import java.awt.image.*;
    import java.lang.*;
    import java.awt.Graphics;
    public class eg31662 extends Applet implements ActionListener
        Panel panel1, panel2, panel3, panel4, panel5;
        Button login, enter;
        Label inst, top, admin, pass, startLabel;
        TextField adminF, passF, field;
        String Admin, Password;
        Vector admins, passwords;
         //Quiz declarations
         TextField ansF1,ansF2,ansF3;
         Button startBut, next0, next1, finishB, previous1;
         Image q1, q2, q3;
         Image ques[] = new Image[2];
         boolean text = false;
         boolean checked = false;
         int correct = 0;
         String [] answer = new String [2];
         String [] solution = {"11", "22", "33"};
         boolean text = false;
         boolean sound = true;
         int red,green,blue;
         int question =0;
         int good = 0;
         boolean pause= false;
         boolean start = true;*/
        Thread thread = null;
        boolean status = false;
        public void init()
            validateUser();
            setLayout (new BorderLayout());
            panel1 = new Panel(new FlowLayout());
            panel2 = new Panel(new FlowLayout());
            panel3 = new Panel(new FlowLayout());
            //login button
            login = new Button("Login");
            //instruction
            inst = new Label("Please type in your UserName and the given " +
                             "password in order to proceed");
            //label
            top = new Label("Top Label");
            admin = new Label("User Name :");
            pass = new Label("Password :");
            //input textfields
            adminF = new TextField(8);
            passF = new TextField(10);
            passF.setEchoChar('*');
            panel1.setBackground(Color.gray);
            panel2.setBackground(Color.orange);
              panel3.setBackground(Color.gray);
            panel2.add(admin);
            panel2.add(adminF);
            panel2.add(pass);
            panel2.add(passF);
            panel2.add(login);
            panel3.add(inst);
            panel1.add(top);
            add(panel1, BorderLayout.NORTH);
            add(panel2, BorderLayout.CENTER);
            add(panel3, BorderLayout.SOUTH);
            login.addActionListener(this);
            setSize(500,400);
        private void validateUser()
            String[] adminData    = {"t", "User1", "User2", "User3"};
            String[] passwordData = {"t", "P1", "P2", "P3"};
            admins = new Vector();
            passwords = new Vector();
            for(int j = 0; j < adminData.length; j++)
                admins.add(adminData[j]);
                passwords.add(passwordData[j]);
        private void Mainpage()
            boolean flag = true;
            removeAll();  // remove all components from container
            panel1 = new Panel(new FlowLayout());
            panel2 = new Panel(new FlowLayout());
              panel3 = new Panel(new FlowLayout());
            top = new Label("Welcome");
            enter = new Button("Enter");
            panel2.setBackground(Color.orange);
            panel1.setBackground(Color.gray);
            panel3.setBackground(Color.gray);
            startLabel = new Label("Welcome! " +
                                          "Please click on the 'Start' button to begin the quiz ");
              startBut = new Button("Start");
              startBut.requestFocus();
              Dimension dim = getSize();
              startBut.setSize(50,20);
            add(panel1, BorderLayout.NORTH);
            add(panel2, BorderLayout.CENTER);
            add(panel3, BorderLayout.SOUTH);
            panel2.add(startLabel);
            panel2.add(startBut);
            startBut.addActionListener(this);
            validate();
            repaint();
        private void Quiz1()
              //quizCanvas = new Canvas();
            boolean flag = true;
            removeAll();  // remove all components from container
            panel1 = new Panel(new FlowLayout());
            panel2 = new Panel(new FlowLayout());
            panel3 = new Panel(new FlowLayout());
            panel1.setBackground(Color.gray);
            panel2.setBackground(Color.orange);
            panel3.setBackground(Color.gray);
            add(panel1, BorderLayout.NORTH);
            add(panel2, BorderLayout.CENTER);
            add(panel3, BorderLayout.SOUTH);
              q1 = getImage(getDocumentBase(), "1.gif");
              ques[0] = q1;
              //ques[1] = q2;
              //previous = new Button("<");
              next0 = new Button("Done");
            ansF1 = new TextField(25);
              next0.addActionListener(this);
              //quizCanvas.insert(ques1);
            //panel3.add(previous);
            panel3.add(next0);
            panel3.add(ansF1);
            //panel2.add("1.gif");
              ansF1.requestFocus();
              ansF1.setText("focussing");
            validate();
            repaint();
         public void Quiz2(){
            boolean flag = true;
            removeAll();  // remove all components from container
            panel1 = new Panel(new FlowLayout());
            panel2 = new Panel(new FlowLayout());
            panel3 = new Panel(new FlowLayout());
            panel1.setBackground(Color.gray);
            panel2.setBackground(Color.orange);
            panel3.setBackground(Color.gray);
            add(panel1, BorderLayout.NORTH);
            add(panel2, BorderLayout.CENTER);
            add(panel3, BorderLayout.SOUTH);
              q2 = getImage(getDocumentBase(), "2.gif");
              ques[1] = q2;
              next1 = new Button("Done");
            ansF2 = new TextField(25);
              next1.addActionListener(this);
            panel3.add(next1);
            panel3.add(ansF2);
              ansF2.requestFocus();
              ansF2.setText("focussing");
            validate();
            repaint();
         public void Quiz3(){
            boolean flag = true;
            removeAll();  // remove all components from container
            panel1 = new Panel(new FlowLayout());
            panel2 = new Panel(new FlowLayout());
            panel3 = new Panel(new FlowLayout());
            panel1.setBackground(Color.gray);
            panel2.setBackground(Color.orange);
            panel3.setBackground(Color.gray);
            add(panel1, BorderLayout.NORTH);
            add(panel2, BorderLayout.CENTER);
            add(panel3, BorderLayout.SOUTH);
              q3 = getImage(getDocumentBase(), "3.gif");
              ques[2] = q3;
              finishB = new Button("Finish");
            ansF3 = new TextField(25);
              finishB.addActionListener(this);
            panel3.add(finishB);
            panel3.add(ansF3);
              ansF3.requestFocus();
              ansF3.setText("focussing");
            validate();
            repaint();
        public void start() {
            if(thread == null) {
                status = true;
        public void stop() {
            status = false;
        public void actionPerformed(ActionEvent ev)
            boolean ok = true;
            if(ev.getSource() == login)
                Admin = adminF.getText();
                Password = passF.getText();
                for (int i = 0; i < admins.size(); i++) {
                    if (Admin.equals(admins.get(i).toString())) {
                        if (Password.equals(passwords.get(i).toString())) {
                            ok = true;
                            JOptionPane.showMessageDialog(null,
                                        "Welcome, u have successfully logged in");
                            Mainpage();
                            break;
                        else {
                            ok = false;
                    else {
                        ok = false;
                if (!ok) {
                    JOptionPane.showMessageDialog(null,
                                  "Incorrect Password or Admin No, Please Try Again",
                                  "Access Denied",
                                   JOptionPane.ERROR_MESSAGE);
            if(ev.getSource() == startBut)
                   Quiz1();
              if (ev.getSource () == next0) {
                   saveanswer();
                   Quiz2();
              if (ev.getSource () == next1) {
                   //saveanswer();
                   Quiz3();
              if (ev.getSource () == finishB) {
                   //saveanswer();
                   //checkanswer();
         /*class quizCanvas extends Canvas {
              private Image quest;
              public quizCanvas() {
                   this.quest = null;
              public quizCanvas(Image quest) {
                   this.quest = quest;
              public void insert(Image quest) {
                   this.quest=quest;
                   repaint();
              public void paint(Graphics g) {
         public void checkanswer() {
              if (!checked) {
              /*question = 0;
                   for (int a=1;a<16;a++) {
                        question++;*/
                        if (ansF1) {
                             if (answer[1].toUpperCase().equals(solution[1])) {
                                  correct++;
                        if (ansF2) {
                             if (answer[2].toUpperCase().equals(solution[2])) {
                                  correct++;
                        if (ansF3) {
                             if (answer[3].toUpperCase().equals(solution[3])) {
                                  correct++;
              checked = true;     }
         public void saveanswer() {
              if (text) {
                   if (!ansF1.getText().equals("")) {
                        answer [Quiz1] = ansF1.getText();
                   //answer2[question] = tf2.getText();
                   if (!ansF2.getText().equals("")) {
                        answer [] = ansF2.getText();
                   if (!ansF3.getText().equals("")) {
                        answer [] = ansF3.getText();
    }

Maybe you are looking for

  • Pc suite 7.0.8.2 no new messages after unicode SMS...

    I was using 7.0.8.2 on XP quite happily until a strange problem appeared. after receiving a multipart unicode SMS on my 6300, pc suite was no longer aware of any new messages - i.e. when I look at the "inbox", it had every message up to the unicode (

  • I used find my iphone yesterday (my daughters iphone6)

    I used the "Find my Iphone" app (have been using to keep track of my daughter) and I check her frequent locations as well...so far in the frequent locations until last week they had all been pretty accurate but there is one location that puts her not

  • KKBC_ORD report - filtering by Cost Centre

    Hi, I was trying to filter KKBC_ORD report for Confirmation Transactions to show only a specified cost centre. I set up a filter on cost centre column, but when I specify cost centre and confirm this filtering, it shows no data even though this cost

  • I signed up via email can i define a username?

    Hi so A long time ago i signed up for skype via my email address. but now my name is live:c***** is there any chance i could define a custom username that i can sign into third party apps with, also so its easier to share my details with someone to a

  • Manually set IP addresses not working as needed

    We have setup our DCHP server in that we manually not dynamically give IP addresses to workstations according to there mac addresses. But most of the time the the workstations go and get the IP addresses dynamically, and in this case most of the time