Repaint in JApplet ?

I use setVisible for showing my components (in JApplet)
but if window was resized or hidden by another
it's not showing again.how can i fix it ?
Thanks

I use setVisible for showing my components (in JApplet)
but if window was resized or hidden by another
it's not showing again.how can i fix it ?
Thanks

Similar Messages

  • 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

  • JOptionPane and Applet problem

    Hi folks,
    I have an applet, I want to display a pop up dialog whenever the user
    does something. SO i used JOptionPane:
    int userIn=JOptionPane.showInternalConfirmDialog(this,"Do you wish to generate xml for each ics/ids files pair in this data set?", "information",JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
    //repaint();
    The dialog just doesn't show up, I tried repaint(), tried JApplet, nothing works, what am I missing? I'm pretty sure the above code gets called.
    thanks

    A. Are you sure this code is executing?
    B. Are you sure you aren't getting an error, possibly something like
    java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
    at javax.swing.JOptionPane.createInternalFrame(JOptionPane.java:1161)
    at javax.swing.JOptionPane.showInternalOptionDialog(JOptionPane.java:1025)
    at javax.swing.JOptionPane.showInternalConfirmDialog(JOptionPane.java:967)
    at javax.swing.JOptionPane.showInternalConfirmDialog(JOptionPane.java:931)

  • Avoiding the repaint of all components in an JApplet

    Hello everyone,
    Thannks to all who gave me advices for the two JComboBoxes I had...finally I found two "if" conditions in the actionPerformed of the first JComboo which restricted the list of elements posted in the second one.
    I have a much bigger problem now....The Applet contains an object which is an extension of JPanel, and in this extension there is a "paintComponent()" that creates a certain number of JButtons in a "for" loop. The problem I have is :
    How could I avoid this panel to be repainted every time the page containing the Applet is resized? Is it even possible( because from what I've been reading a "paint()" of the applet always calls for all the components' "repaint()".....I haven't even definned a "paint()" for the applet, .....and then, each button has an action listener that simply won't work after a repaint() of the whole applet. And honestly i'm starting to lose my mind a bit over all this......Oh, I had almost forgotten....the problem after re-sizing is that within the borders of the Panel there are always buttons created by the "for" loop ....and they are smaller and appear high up "north" in the panel...it's horrible!!!!!
    This is my code for the paintComponent() of the extension of the JPanel:
    public void paintComponent(Graphics g){
           g.drawLine (130,50,130,450);
           g.drawLine (129,50,129,450);
           g.drawLine (270,50,270,450);
           g.drawLine (271,50,271,450);
           g.drawString("Plateau no.", 80,40);
           g.setColor(ballon);
           g.fillArc(100,434,200,100,45,-270);
           System.out.println("I've been through paint");
        for(int i=0;i<13;i++)
           System.out.println("buton ok"+i);
           plateaux=new JButton();
    plateaux[i].setEnabled(true);
    plateaux[i].addActionListener(this);
    Color cri=new Color(240-15*i,0,0);
    plateaux[i].setBounds(130,60+30*i,139,15);
    plateaux[i].setBackground(cri);
    add(plateaux[i], null);
    g.drawString(" "+ (13-i),105,70+30*i);
    There's nothing else in the extension....only the paint ...it implements ActionListener.....
    Thankx in advance....I'd really apreciate it if someone could help me.....
    Ruxi

    To clear the background for each repaint add a call to super or use clearRect or fillRect (with the background color set, of course). If you don't do this you will get artifacts in your graphics.
    class GraphicComponent extends JPanel {
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            // carry on...
    }Paint code is the place to render graphics and images, not for adding components. Add your components to the GUI in or via init. Generally is is useful to keep your drawing component separate from your other components.
    class GUIClass extends JApplet implements ActionListener {
        public void init() {
            JPanel buttonPanel = getButtonPanel();
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(buttonPanel, "South");
            getContentPane().add(new GraphicComponent());  // default center section
        private JPanel getButtonPanel() {
            JPanel panel = new JPanel(null);
            JButton[] plateaux = nw JButton[13];
            for(int i=0;i<plateaux.length;i++) {
                System.out.println("buton ok"+i);
                plateaux=new JButton("button " + i);
    plateaux[i].setEnabled(true);
    plateaux[i].addActionListener(this);
    Color cri=new Color(240-15*i,0,0);
    plateaux[i].setBounds(130,60+30*i,139,15);
    plateaux[i].setBackground(cri);
    panel.add(plateaux[i]);

  • Repainting menu bar for JApplet

    I have a menu bar (JMenuBar) that is set to the JApplet. The menu bar shows up fine when the applet is loaded but
    when I resize browser it does not repaint itself. I tried to override the paint method of JApplet and called paintComponents() method. The GUI shows up but menu bar does not repaint itself. I also tried to call repaint() method, but nothing (GUI + menu bar) shows up on the browser.
    Any suggestions.
    Thanks for you patience.
    Kumar

    Please ignore this question.
    I got that fixed.
    Thanks
    Kumar

  • Need to convert JApplet to JFrame

    I need to write code for where I have 60 balls bouncing around inside a window. The client will then be able to select a button and it will pull out a ball with the number 1-60 written on it. The user will be able to do this up to 7 times. Each time it is done the past numbers that have already appeared can not reappear. What I am stuck on right now is geting my balls into a JFrame. Can anyone give advice or show how to. I currently have my 60 balls running in a JApplet. Here is the JAVA code and the HTML code. Thanks!
    Here is the JAVA code
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import javax.swing.*;
    class CollideBall{
    int width, height;
    public static final int diameter=20;
    //coordinates and value of increment
    double x, y, xinc, yinc, coll_x, coll_y;
    boolean collide;
    Color color;
    Graphics g;
    Rectangle r;
    //the constructor
    public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c){
    width=w;
    height=h;
    this.x=x;
    this.y=y;
    this.xinc=xinc;
    this.yinc=yinc;
    color=c;
    r=new Rectangle(150,80,130,90);
    public double getCenterX() {return x+diameter/2;}
    public double getCenterY() {return y+diameter/2;}
    public void alterRect(int x, int y, int w, int h){
    r.setLocation(x,y);
    r.setSize(w,h);
    public void move(){
    if (collide){  
    double xvect=coll_x-getCenterX();
    double yvect=coll_y-getCenterY();
    if((xinc>0 && xvect>0) || (xinc<0 && xvect<0))
    xinc=-xinc;
    if((yinc>0 && yvect>0) || (yinc<0 && yvect<0))
    yinc=-yinc;
    collide=false;
    x+=xinc;
    y+=yinc;
    //when the ball bumps against a boundary, it bounces off
    if(x<6 || x>width-diameter){
    xinc=-xinc;
    x+=xinc;
    if(y<6 || y>height-diameter){
    yinc=-yinc;
    y+=yinc;
    //cast ball coordinates to integers
    int x=(int)this.x;
    int y=(int)this.y;
    //bounce off the obstacle
    //left border
    if(x>r.x-diameter&&x<r.x-diameter+7&&xinc>0&&y>r.y-diameter&&y<r.y+r.height){
    xinc=-xinc;
    x+=xinc;
    //right border
    if(x<r.x+r.width&&x>r.x+r.width-7&&xinc<0&&y>r.y-diameter&&y<r.y+r.height){
    xinc=-xinc;
    x+=xinc;
    //upper border
    if(y>r.y-diameter&&y<r.y-diameter+7&&yinc>0&&x>r.x-diameter&&x<r.x+r.width){
    yinc=-yinc;
    y+=yinc;
    //bottom border
    if(y<r.y+r.height&&y>r.y+r.height-7&&yinc<0&&x>r.x-diameter&&x<r.x+r.width){
    yinc=-yinc;
    y+=yinc;
    public void hit(CollideBall b){
    if(!collide){
    coll_x=b.getCenterX();
    coll_y=b.getCenterY();
    collide=true;
    public void paint(Graphics gr){
    g=gr;
    g.setColor(color);
    //the coordinates in fillOval have to be int, so we cast
    //explicitly from double to int
    g.fillOval((int)x,(int)y,diameter,diameter);
    g.setColor(Color.white);
    g.drawArc((int)x,(int)y,diameter,diameter,45,180);
    g.setColor(Color.darkGray);
    g.drawArc((int)x,(int)y,diameter,diameter,225,180);
    public class BouncingBalls extends Applet implements Runnable {
    Thread runner;
    Image Buffer;
    Graphics gBuffer;
    CollideBall ball[];
    //Obstacle o;
    //how many balls?
    static final int MAX=60;
    boolean intro=true,drag,shiftW,shiftN,shiftE,shiftS;
    boolean shiftNW,shiftSW,shiftNE,shiftSE;
    int xtemp,ytemp,startx,starty;
    int west, north, east, south;
    public void init() {  
    Buffer=createImage(getSize().width,getSize().height);
    gBuffer=Buffer.getGraphics();
    ball=new CollideBall[MAX];
    int w=getSize().width-5;
    int h=getSize().height-5;
    //our balls have different start coordinates, increment values
    //(speed, direction) and colors
    for (int i = 0;i<60;i++){
    ball=new CollideBall(w,h,50+i,20+i,1.5,2.0,Color.white);
    /* ball[1]=new CollideBall(w,h,60,210,2.0,-3.0,Color.red);
    ball[2]=new CollideBall(w,h,15,70,-2.0,-2.5,Color.pink);
    ball[3]=new CollideBall(w,h,150,30,-2.7,-2.0,Color.cyan);
    ball[4]=new CollideBall(w,h,210,30,2.2,-3.5,Color.magenta);
    ball[5]=new CollideBall(w,h,360,170,2.2,-1.5,Color.yellow);
    ball[6]=new CollideBall(w,h,210,180,-1.2,-2.5,Color.blue);
    ball[7]=new CollideBall(w,h,330,30,-2.2,-1.8,Color.green);
    ball[8]=new CollideBall(w,h,180,220,-2.2,-1.8,Color.black);
    ball[9]=new CollideBall(w,h,330,130,-2.2,-1.8,Color.gray);
    ball[10]=new CollideBall(w,h,330,10,-2.1,-2.0,Color.gray);
    ball[11]=new CollideBall(w,h,220,230,-1.2,-1.8,Color.gray);
    ball[12]=new CollideBall(w,h,230,60,-2.3,-2.5,Color.gray);
    ball[13]=new CollideBall(w,h,320,230,-2.2,-1.8,Color.gray);
    ball[14]=new CollideBall(w,h,130,300,-2.7,-3.0,Color.gray);
    ball[15]=new CollideBall(w,h,210,90,-2.0,-1.8,Color.gray);*/
    public void start(){
    if (runner == null) {
    runner = new Thread (this);
    runner.start();
    /* public void stop(){
    if (runner != null) {
    runner.stop();
    runner = null;
    public void run(){
    while(true) {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    try {runner.sleep(15);}
    catch (Exception e) { }
    //move our balls around
    for(int i=0;i<MAX;i++)
    ball[i].move();
    handleCollision();
    repaint();
    boolean collide(CollideBall b1, CollideBall b2){
    double wx=b1.getCenterX()-b2.getCenterX();
    double wy=b1.getCenterY()-b2.getCenterY();
    //we calculate the distance between the centers two
    //colliding balls (theorem of Pythagoras)
    double distance=Math.sqrt(wx*wx+wy*wy);
    if(distance<b1.diameter)
    return true;
    return false;
    private void handleCollision()
    //we iterate through all the balls, checking for collision
    for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
    if(i!=j)
    if(collide(ball[i], ball[j]))
    ball[i].hit(ball[j]);
    ball[j].hit(ball[i]);
    public void update(Graphics g)
    paint(g);
    public void paint(Graphics g)
    gBuffer.setColor(Color.lightGray);
    gBuffer.fillRect(0,0,getSize().width,getSize().height);
    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
    //paint our balls
    for(int i=0;i<MAX;i++)
    ball[i].paint(gBuffer);
    g.drawImage (Buffer,0,0, this);
    Here is the HTML code
    <html>
    <body bgcolor="gray">
    <br><br>
    <div align="center">
    <applet code="BouncingBalls.class" width="1000" height="650"></applet>
    </div>
    </body>
    </html>

    In the future, Swing related questions should be posted in the Swing forum.
    First you need to convert your custom painting. This is done by overriding the paintComponent() method of JComponent or JPanel. Read the Swing tutorial on [Custom Painting|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html].
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.

  • How to update a JPanel in a JApplet

    Hi All,
    I'm trying to make my own sudoku JApplet. JApplet uses a BorderLayout() adding the sudoku Puzzle in the center, JButtons for New Games in a JPanel in the west and a GridLayout(3,3) to select the number to put in the puzzle in the east.
    The problem is: how can i update the sudoku puzzle in the center by clicking the "new game" JButton in the west?
    I use JButtons to represent numbers in the puzzle. this is how i create the JButton and set its ActionListener().
         public static JButton casella(String[] casella) {
              final JButton b = new JButton(casella[0]);
              b.setFont(new Font("SansSerif",Font.BOLD,33));
              if(casella[3].equals("1"))
                   b.setBorder(BorderFactory.createLineBorder(Color.orange));
              if(casella[3].equals("2"))
                   b.setBorder(BorderFactory.createLineBorder(Color.red));
              else
                   b.setBorder(BorderFactory.createLineBorder(Color.black));
              b.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        if(Sudoku.NUMERO_CORRENTE>=0)
                             b.setText(String.valueOf(Sudoku.NUMERO_CORRENTE));
                        else
                             b.setText("_");
              return b;
         }this is the main class:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Sudoku extends JApplet {
         static String[][][] MATRICE = MatriceCompleta.sudoku().getArrayMatrice();
         static JPanel PANNELLO_NUMERICO = OggettiGrafici.pannelloNumerico();
         static JPanel PANNELLO_EAST = new JPanel(new GridLayout(3,1));
         static JPanel PANNELLO_WEST = new JPanel(new GridLayout(6,1));
         static JPanel PANNELLO_CASELLE = new JPanel(new GridLayout(3,3));
         static JPanel PANNELLO = new JPanel(new BorderLayout());
         static int POSIZIONE_CASELLA_X = 0;
         static int POSIZIONE_CASELLA_Y = 0;
         static int NUMERO_CORRENTE = 0;
         static JLabel LABEL_NUMERO_CORRENTE = new JLabel(String.valueOf(NUMERO_CORRENTE), JLabel.CENTER);
         static JLabel LABEL_PARTITA = new JLabel("",JLabel.CENTER);
         static JLabel LABEL_NUOVA_PARTITA = new JLabel("NUOVA PARTITA",JLabel.CENTER);
         static JButton FACILE = new JButton("Livello Facile");
         static JButton NORMALE = new JButton("Livello Medio");
         static JButton DIFFICILE = new JButton("Livello Difficile");
         static JButton CONTROLLA_ERRORI = new JButton("Controlla Errori");
         static JButton CANCELLA_NUMERO = new JButton("Cancella Numero");
         static String DIFFICOLTA = "NORMALE";
         static int i, j, k;
         public void init() {
              String[][][][] divisaInPannelli = ComandiUtili.divisioneInPannelli(MATRICE);
              JPanel p0 = new JPanel(new GridBagLayout());
              JPanel p1 = new JPanel(new GridBagLayout());
              JPanel p2 = new JPanel(new GridBagLayout());
              JPanel p3 = new JPanel(new GridBagLayout());
              JPanel p4 = new JPanel(new GridBagLayout());
              JPanel p5 = new JPanel(new GridBagLayout());
              JPanel p6 = new JPanel(new GridBagLayout());
              JPanel p7 = new JPanel(new GridBagLayout());
              JPanel p8 = new JPanel(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.BOTH;
                    // creating the sudoku puzzle panel using JButtons
              for(i=0;i<9;i++) {
                   for(j=0;j<3;j++) {
                        for(k=0;k<3;k++) {
                             JButton b = OggettiGrafici.casella(divisaInPannelli[i][k][j]);
                             c.gridx = j;
                             c.gridy = k;
                             c.ipadx = 42;
                             c.ipady = 12;
                             if(i==0)
                                  p0.add(b,c);
                             else if(i==1)
                                  p1.add(b,c);
                             else if(i==2)
                                  p2.add(b,c);
                             else if(i==3)
                                  p3.add(b,c);
                             else if(i==4)
                                  p4.add(b,c);
                             else if(i==5)
                                  p5.add(b,c);
                             else if(i==6)
                                  p6.add(b,c);
                             else if(i==7)
                                  p7.add(b,c);
                             else if(i==8)
                                  p8.add(b,c);
              PANNELLO_CASELLE.add(p0);
              PANNELLO_CASELLE.add(p1);
              PANNELLO_CASELLE.add(p2);
              PANNELLO_CASELLE.add(p3);
              PANNELLO_CASELLE.add(p4);
              PANNELLO_CASELLE.add(p5);
              PANNELLO_CASELLE.add(p6);
              PANNELLO_CASELLE.add(p7);
              PANNELLO_CASELLE.add(p8);
              PANNELLO_EAST.add(PANNELLO_NUMERICO);
              PANNELLO_EAST.add(LABEL_NUMERO_CORRENTE);
              PANNELLO_EAST.add(LABEL_PARTITA);
              PANNELLO_WEST.add(LABEL_NUOVA_PARTITA);
              PANNELLO_WEST.add(FACILE);
              PANNELLO_WEST.add(NORMALE);
              PANNELLO_WEST.add(DIFFICILE);
              PANNELLO_WEST.add(CONTROLLA_ERRORI);
              PANNELLO_WEST.add(CANCELLA_NUMERO);
              PANNELLO.add(PANNELLO_CASELLE, BorderLayout.CENTER);
              PANNELLO.add(PANNELLO_EAST, BorderLayout.EAST);
              PANNELLO.add(PANNELLO_WEST, BorderLayout.WEST);
              add(PANNELLO);
         public void paint(Graphics g) {
              super.paint(g);
    }How can i update the sudoku puzzle (JPanel with 9x9 JButtons) by clicking on a "new game" JButton?
    Thank You very much in advance!

    Hi SD,
    How are you drawing the image on the JPanel?
    Are you using JLabel with image and adding it to Panel or using
    drawImage to get the image on the panel (Only jpeg and gif formats are supported here).
    DrawImage should automatically refresh, if not call repaint().
    That should refresh the Screen.
    Regards
    Chandra Mohan

  • Problem with Thread in JApplet

    Hi,
    I am working on a project on pseudo random functions, and for that matter I have written a problem. Now I am working on a user interface (JApplet) for my program. Because some heavy calculations can occur, I want to keep track of the progress, and show that in my JApplet. To do so, I start a Thread in which the calculations take place. In my JApplet I want to show every second how far the proces is done. The strange thing is, that the status JLabel only appears when the whole proces is done, and the start button keeps pressed during the proces. If I run this in the applet viewer, I can see the status every second in my command box. You can see the applet here : applet
    The code concerning the start button's actionlistener (entire appletcode: [applet code|http://www.josroseboom.nl/PseudoRandomClusteringApplet.java]) :
              if(e.getSource()==start)
                   int[][] randomFuncties = new int[current+1][5];
                   int puntenHuidige, g, q, y, m, f;
                   boolean done;
                   Kern k;
                   for(int i = 0;i<=current;i++)
                        randomFuncties[i] = functies.getValues();
                   invoer.remove(knopjes);
                   startTijd = System.currentTimeMillis();
                   proces.setBounds(25,(current+4)*25, 2*this.getWidth()/3,75);
                   invoer.add(proces);
                   this.validate();
                   this.repaint();
                   for(int i = 0;i<=current;i++)
                        puntenHuidige = 0;
                        f = randomFuncties[i][0]; // important for instantiation of k, which is cut out here
                        done = false;
                        k.start();     // k is a Thread where heavy calculations are done
                        ((JLabel)(proces.getComponent(2))).setText("points done of current (" + q + ")");
                        this.repaint();
                        while(!done)
                             ((JLabel)(proces.getComponent(1))).setText("" + convertTime(System.currentTimeMillis() - startTijd));
                             ((JLabel)(proces.getComponent(3))).setText("" + k.getPuntenGehad()); // get the point done so far
                             ((JLabel)(proces.getComponent(5))).setText("" + ((100*k.getPuntenGehad())/q) + "%");
                             debug("q: " + q);
                             debug("point done: " + k.getPuntenGehad());
                             if(k.getPuntenGehad()==q)     //if all points are considered
                                  done=true;
                             this.validate();
                             this.repaint();
                             try
                                  Thread.sleep(1000);
                             catch(InterruptedException exception)
                                  debug("foutje met slapen: InterruptedException");
                             catch(IllegalMonitorStateException exception)
                                  debug("foutje met wachten: IllegalMonitorStateException");
                             debug("IN APPLET: yet another loop walk");
                        stringResultaten.add(k.geefResultaat());
                   klaarLabel.setBounds(this.getWidth()/4,(current+8)*25, this.getWidth()/2,25);
                   naarResultaat.setBounds(25+this.getWidth()/4,(current+9)*25, this.getWidth()/4,25);
                   invoer.add(klaarLabel);
                   invoer.add(naarResultaat);
                   this.validate();
                   this.repaint();
    Edited by: Jos on Sep 19, 2007 1:22 AM

    Never do anything that takes more than a fraction of a second in an actionPerformed method or similar GUI callback.
    The GUI stuff is all handled by a single thread called the "AWT Dispatcher" thread. That includes code in such callbacks. While it's executing your callback it can't do any kind of screen updating or response to other user events.
    Instead your actionPerformed should work with a separater "worker" thread, either it should launch a new thread, or release one you create (using wait and notify). Then, it returns without waiting. When the worker thread wants to update the GUI it uses EventQueue.invokeLater() or invokeAndWait() to run some (fast) code on the Dispatcher thread.

  • Help please, not able to load images in a subclass of a japplet

    I've created this board for a project, but now I am stuck, I cannot seem to get images to appear, instead they come up as a nullpointerexception:
    public class Board extends JLayeredPane implements MouseListener, MouseMotionListener{
         private Container contentPane;
         private JLayeredPane jlp;     
         private boolean pieceSelected;
         private timepanel time;
         Image bimage;
         ImageIcon board;
         JLabel brd;
         Image pimage;
         ImageIcon piece;
         JLabel pce;
         private Graphics g;
         private pieceLayout pieces;
         private String piecename;
         private JLabel jl;
         boolean selected;
         private int offset;
         boolean changepos;
         boolean moving;
         private int brdwidth;
         private int brdheight;
         private Timer countdown;
         private updateTimer ut;
         private String cb;
         private clientinterface ci;
         private JFrame j;
         private int playerturn;
         public Board(clientinterface ci, JFrame j, Hashtable images, ArrayList names,
         ImageIcon brdicon, URL cb)
              j.setSize(500,450);
              countdown = new Timer();
              selected = false;
              jlp = this;
              jlp.setPreferredSize(new Dimension(500, 450));
              changepos = false;
              //contentPane = getContentPane();
              //this.setPreferredSize(new Dimension(500,400));
              jlp.setBounds(0,0,500,450);
              jlp.setLocation(0,0);
              jlp.setOpaque(true);
              jlp.setLayout(null);
              System.out.println(this.getSize() + "(((())))" );
              if(j.getWidth() > 400)
                   offset = j.getWidth() - 400;
              else
                   offset = 0;
              System.out.println("Width is: " +  j.getWidth() + " height: " + j.getHeight());     
              brdwidth = j.getWidth()-offset;
              brdheight = j.getHeight();
              System.out.println(images.size());     
              System.out.println(j.getWidth() + " " + j.getHeight() + " " + offset);
              brd = new JLabel(brdicon);
              brd.setBounds(0,0,j.getWidth()-offset, j.getHeight());
              brd.setSize(new Dimension(400,400));
              brd.setLocation(0,0);
              brd.setOpaque(true);
              jlp.add(brd, new Integer(-5));
              jlp.setBounds(0,0,j.getWidth(), j.getHeight());
              jlp.setVisible(true);
              time = new timepanel(jlp);
              time.setLocation(j.getWidth()-offset, 0);
              System.out.println(images.toString() + "++++++++");
              pieces = new pieceLayout(jlp, j.getWidth()-offset, names, cb);
              pieces.setLocation(0,0);
              pieces.setPreferredSize(new Dimension(400,400));
              pieces.setBounds(0,0,400,400);
              pieces.setVisible(true);
              time.setBounds(400,0, 100, 400);
              time.setVisible(true);
              ut = new updateTimer(time);
              jlp.add(pieces, new Integer(2));
              jlp.add(time, new Integer(2));
              //this.add(jlp);
              j.setLayeredPane(jlp);
              addMouseMotionListener(this);
              addMouseListener(this);
              //j.getContentPane().add(jlp);
              //j.setContentPane(this);
              j.validate();
              //j.getContentPane().setLayout(null);
              //j.setContentPane(this);
              j.paintAll(j.getGraphics());
         public void run()
              //this.repaint();
              this.paintAll(this.getGraphics());
              time.repaint();
         public void mouseDragged(MouseEvent e)
              JLabel temp;
              moving = true;
              //pce.setLocation(e.getX(), e.getY());
              //pieces.getPiece(pieces.translatecoords(e.getX(),e.getY())).setLocation(e.getX(),e.getY());
              int piecepos = pieces.translatecoords(e.getX(), e.getY());
              /*if(pieces.hasPiece(piecepos) && moving)
                   pieces.setSelected(piecepos);
                   temp = pieces.getPiece(piecepos);
                   //pieces.movePiece(e.getX(), e.getY());
                   temp.setLocation(e.getX(), e.getY());
              //this.repaint();
         public void mouseClicked(MouseEvent e)
              Point xpoin;
              System.out.println("Hello, clicked");
              /*pce.setLocation(e.getX(), e.getY());
              Point p = pce.getLocation();
              System.out.println(p.toString());*/
              System.out.println("\n" + e.getX() + " " + e.getY());
         public void mouseEntered(MouseEvent e)
         public void mouseExited(MouseEvent e)
         public void mouseReleased(MouseEvent e)
              if(selected)
                   Point xp;
                   int x = e.getX();
                   int y = e.getY();
                   int bp = pieces.translatecoords(x,y);
                   xp = pieces.posToPoint(bp);
                   pieces.snapToSquare(xp.x, xp.y, bp);
                   selected = false;
                   moving = false;
                   //pieces.updateBoard(bp, piecename);
         public void mouseMoved(MouseEvent e)
         public void mousePressed(MouseEvent e)
              Point xpoin;
              int pos = pieces.translatecoords(e.getX(),e.getY());
              System.out.println("\n" + pieces.translatecoords(e.getX(),e.getY()));
              if(pieces.hasPiece(pos, e.getX(), e.getY()))
                        piecename = pieces.getName(pos);
                        System.out.println("Found a piece!");
                        pieces.setSelected(pos);
                        xpoin = pieces.posToPoint(pos);
                        selected = true;
         public void paintComponent(Graphics g)
              //super.paintComponents(g);
              //System.out.println("Painting");
              time.repaint();
         public void start()
              countdown.schedule(ut, 0, 1000);
         public void setupBoard()
                   //setSize(getSize().width < 400 ? 400 : getSize().width,
                   //getSize().height < 400 ? 400 : getSize().height);
                   //getLayeredPane().add(brd, new Integer(-5));
         public void sendInfo(String info)
              //parse information
         public class pieceLayout extends JLayeredPane
              JLabel pce1;
              private JLabel selected;
              private Hashtable pieceList;
              private ArrayList names;
              private int width;
              private Hashtable piecesOnBoard;
              private char boardstate[]= {'R','N','B','Q','K','B','N','R',
                                                 'P','P','P','P','P','P','P','P',
                                                 'p','p','p','p','p','p','p','p',
                                                 'r','n','b','q','k','b','n','r'
              private String posnm[]       = {
                                                       "a8", "b8", "c8", "d8", "e8", "f8", "g8", "h8",
                                                       "a7", "b7", "c7", "d7", "e7", "f7", "g7", "h7",
                                                       "a6", "b6", "c6", "d6", "e6", "f6", "g6", "h6",
                                                       "a5", "b5", "c5", "d5", "e5", "f5", "g5", "h5",
                                                       "a4", "b4", "c4", "d4", "e4", "f4", "g4", "h4",
                                                       "a3", "b3", "c3", "d3", "e3", "f3", "g3", "h3",
                                                       "a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2",
                                                       "a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1"
              JLayeredPane thePane;
              private Hashtable ht;
              private Hashtable board;
              private Hashtable b2p;
              private Hashtable p2b;
              private Hashtable piecePos;
              private Hashtable objToName;
              private Hashtable posnames;
              private URL codebase;
              public pieceLayout(JLayeredPane p, int twidth, ArrayList pnames, URL cb)
                   pieceList = new Hashtable(20);
                   codebase = cb;
                   names = pnames;
                   selected = new JLabel();
                   piecesOnBoard = new Hashtable(32);
                   ht = new Hashtable(6);
                   board = new Hashtable(64);
                   b2p = new Hashtable(64);
                   p2b = new Hashtable(64);
                   piecePos = new Hashtable(64);
                   objToName = new Hashtable(32);
                   posnames = new Hashtable(64);
                   fillnames();
                   getImages();
                   setImages();
                   width = twidth;
                   thePane = p;
                   System.out.println(piecesOnBoard.size());
                   showBoard();
              private void fillnames()
                   int size = posnm.length;
                   for(int i = 0; i < size; i++ )
                        posnames.put(new Integer(i), new String(posnm));
                   showPos();
              private void getImages()
                   Pattern p = Pattern.compile(".+\\.GIF");
                   Pattern p1 = Pattern.compile(".+\\.gif");
                   Pattern p2 = Pattern.compile("board.+");
                   Pattern p3 = Pattern.compile(".+board.+");
                   for(int i = 0; i < names.size(); i++)
                        Matcher m = p.matcher((String)names.get(i));
                        Matcher m1 = p1.matcher((String)names.get(i));
                        Matcher m2 = p2.matcher((String)names.get(i));
                        Matcher m3 = p3.matcher((String)names.get(i));
                        if(m.matches() || m1.matches())
                             //System.out.println("Files are: " + dirs[i].getName());
                             if(!m2.matches() && !m3.matches())
                                  String piecename = new String((String)names.get(i));
                                  //     System.out.println("Files were: " + dirs[i].getName());
                                  Image tpimage = Toolkit.getDefaultToolkit().createImage(piecename);
                                  Image pimage = tpimage.getScaledInstance(35,35, Image.SCALE_DEFAULT);
                                  //ImageIcon piece = new ImageIcon(pimage);
                                  pieceList.put(new String(piecename), pimage);
                   System.out.println(pieceList.toString());
                   System.out.println(pieceList.size() + "((**))(())");
              private void setImages()
                   int listsize = names.size();
                   if(!pieceList.isEmpty())
                        int index = 0;
                        for(int i = 0; i < listsize; i++)
                             String pieceName = (String)names.get(index);
                             String hKey = getHashKey(pieceName);
                             System.out.println(hKey);
                             if((hKey.compareTo("blackking") == 0) || (hKey.compareTo("blackqueen") == 0) ||
                             (hKey.compareTo("whiteking") == 0) || (hKey.compareTo("whitequeen") == 0))
                                  Image tpiece = (Image)pieceList.get(new String(hKey));
                                  ImageIcon piece = new ImageIcon(tpiece);
                                  pce1 = new JLabel(piece);
                                  piecesOnBoard.put(new String(hKey), pce1);
                             else
                                  System.out.println("multiples " + hKey);
                                  createMultiples(hKey, pieceName);
                             if(i == listsize-1)
                                  index = 0;
                             else
                                  index++;
                             System.out.println(pieceName + " " + hKey + "1234567890");
              private void createMultiples(String key, String hname)
                   JLabel piecet;
                   String name;
                   if(key == "blackpawn" || key == "whitepawn")
                        name = key;
                        for(int i = 0; i < 8; i++)
                             //System.out.println(name+i);
                             String tempname = name+i;
                             Image piece = (Image)pieceList.get(new String(name));
                             ImageIcon pieces = new ImageIcon(piece);
                             piecet = new JLabel(pieces);
                             piecesOnBoard.put(new String(tempname), piecet);
                   else if(key == "blackknight" || key == "whiteknight")
                        name = key;
                        for(int i = 0; i < 2; i++)
                             //System.out.println(name+i);
                             String tempname = name+i;
                             Image piece = (Image)pieceList.get(new String(name));
                             ImageIcon pieces = new ImageIcon(piece);
                             piecet = new JLabel(pieces);
                             piecesOnBoard.put(new String(tempname), piecet);
                        if(!ht.containsKey(new String(key)))
                             ht.put(new String(key+0), new Integer(0));
                   else if(key == "blackbishop" || key == "whitebishop")
                        name = key;
                        for(int i = 0; i < 2; i++)
                             System.out.println(name+i);
                             String tempname = name+i;
                             Image piece = (Image)pieceList.get(new String(name));
                             System.out.println(piece.toString());
                             ImageIcon pieces = new ImageIcon(piece);
                             piecet = new JLabel(pieces);
                             piecesOnBoard.put(new String(tempname), piecet);
                        if(!ht.containsKey(new String(key)))
                             ht.put(new String(key+0), new Integer(0));
                   else if(key == "blackrook" || key == "whiterook")
                        name = key;
                        for(int i = 0; i < 2; i++)
                             System.out.println(name+i);
                             String tempname = name+i;
                             Image piece = (Image)pieceList.get(new String(name));
                             ImageIcon pieces = new ImageIcon(piece);
                             piecet = new JLabel(pieces);
                             piecesOnBoard.put(new String(tempname), piecet);
                        if(!ht.containsKey(new String(key)))
                             ht.put(new String(key+0), new Integer(0));
    Hopefully this will format alright, but my question is, is that why is it giving me this error... it happens in the create multiples function(the last function in this code block) this is a jlayeredpane which is called by a JApplet. Any ideas on the loading? Its in the getImages() fuction.

    These are the lines it dies on.... the System.out.println(piece.toString()); precisely. I don't know if I am not getting the images from the directory right... or if I need to make sure this is in a JAR file or not.
    {                    name = key;                    for(int i = 0; i < 2; i++)                    {                         System.out.println(name+i);                         String tempname = name+i;                         Image piece = (Image)pieceList.get(new String(name));                         System.out.println(piece.toString());                         ImageIcon pieces = new ImageIcon(piece);                         piecet = new JLabel(pieces);                         piecesOnBoard.put(new String(tempname), piecet);                    }                    if(!ht.containsKey(new String(key)))                    {                         ht.put(new String(key+0), new Integer(0));                    }                    

  • Stuck with the paint and repaint methods

    I am supposed to create a JApplet with a button and a background color. When the button is clicked the first time a word is supposed to appear (I got that part), when the button is clicked the second time the word is supposed to appear again in a different color and in a different location on the Applet (I got that part).
    The problem is that the first name is supposed to disappear when the second word appears. So I know I have to repaint the screen when the button is clicked the second time and draw the first string in the same color as the background color to make it invisible.
    My problem is I am not sure how I can code to apply different settings each time the button is clicked. Can anyone help? Please let me know if my explanation sucks. I will try to explain better. However here is the code I have so far. I added a counter for the button just for testing purposes.
    I just need some hints on what to do and if there is a easier way than using that if statement please let me know. I probably make it harder than it is.
    Thanks in advance and Merry Christmas.
    import javax.swing.*;
       import java.awt.*;
       import java.awt.event.*;
        public class DisplayMyName extends JApplet
        implements ActionListener
          String myName = "DOG";
          String myName1 = "DOG";
          JButton moveButton = new JButton("Move It");
          Font smallFont = new Font("Arial", Font.BOLD, 12);
          Font largeFont = new Font("Lucida Sans", Font.ITALIC, 20);
          int numClicks = 0;
          JLabel label = new JLabel("Number of button clicks:" + numClicks);
           public void init()
             Container con = getContentPane();
             con.setBackground(Color.RED);
             con.setLayout( new FlowLayout() );
             con.add(moveButton);
             con.add(label);
             moveButton.addActionListener(this);
           public void paint(Graphics g)
             numClicks++;
             label.setText("Number of button clicks: " + numClicks);
             if (numClicks == 2)
             { g.setFont(smallFont);
                g.setColor(Color.BLUE);
                g.drawString(myName, 50, 100);
                   else
             if (numClicks == 3)
             { g.setFont(largeFont);
                g.setColor(Color.YELLOW);
                g.drawString(myName, 100, 200);
           public void actionPerformed(ActionEvent move)
             repaint();
       }

    You're putting your program logic in the paint method, something you should not do. For instance, try resizing your applet and see what effect that has on number of button clicks displayed. This is all a side effect of the logic being in the paint method.
    1) Don't override paint, override paintComponent.
    2) Don't draw/paint directly in the JApplet. Do this in a JPanel or JComponent, and then add this to the JApplet. In fact I'd add the button, the and the label to the JPanel and add the label to the JApplet's contentPane (which usually uses BorderLayout, so it should fill the applet).
    3) Logic needs to be outside of paint/paintComponent. the only code in the paintComponent should be the drawing/painting itself. The if statements can remain within the paintComponent method though.
    4) When calling repaint() make sure you do so on the JPanel rather than the applet itself.
    For instance where should numClicks++ go? Where should the code to change the label go? in the paint/paintComponent method? or in the button's actionlistener? which makes more sense?
    Edited by: Encephalopathic on Dec 24, 2008 9:37 AM

  • Passing value from JSP to JApplet

    Hello,
    I am stuck up with a problem, can anyone please tell me how do i pass a value from a JSP page
    to a JApplet,
    and the parameter passed through JSP should be displaed in the JTextArea.
    It would be kindful if any of you could help.
    Thanks
    Sanam

    hello,
    thanks for reply.
    I know how to pass parameters from html,
    I want to pass values from jsp page,
    and i dono how to do it, may be we cann pass values through url connection but i dono how.
    if anone knows plz help me in solving this.
    i hvae posted my applet code.
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    <applet code = "DocApplet" width = 500 height =5000>
    </applet>
    public class DocApplet extends JApplet
         private JPanel jp;
         private Container cp;
         private JTextArea jt;
         private JToolBar tb;     
         private JScrollPane sp;
         private String annotation;
         private String url;
         private Connection con;
         private Statement stmt;
         public void init()
              jp = new JPanel();
              cp = getContentPane();
              jt = new JTextArea();
              tb = new JToolBar();
              sp = new JScrollPane(jt);
              repaint();
         public void start()
              jp.setLayout(new BorderLayout());
              jp.add(tb, BorderLayout.NORTH);
              jp.add(sp, BorderLayout.CENTER);
              jt.setBackground(Color.BLACK);
              jt.setForeground(Color.WHITE);
              setContentPane(jp);
              addButtons(tb);
              repaint();
         public void run()
              repaint();
         public void paint()
         private void addButtons(JToolBar tb)
              JButton button = null;
              button = new JButton("Save");
              button.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
              tb.add(button);
    }

  • Passing value from JApplet to Jsp page

    Hello,
    How can i pass a value that is entered in a JTextArea in a JApplet and fetch the entered value from JTextArea and display it in a JSP page.
    It would be kindful if someone could help me with this problem.
    Regards
    Sanam

    hello,
    Thanks for ur reply,
    Sorry to say that i did not understand where to implement ur code in my code.
    Below is my code could u plz tell me where do i put in ur code.
    My code works fine u can compile it.
    javac *.java;
    appletviewer BIA.java
    Can u plz tell the JSP code.
    It would be very kindful if u could please help me.
    Thank you
    //**************** BIA.java***********
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.util.Vector;     
    import java.applet.*;     
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.lang.reflect.Field;
    <applet code = "BIA" width = 500 height = 500>
    </applet>
    public class BIA extends JApplet
         public static Container cp;
         public BIAP panel;     
         public TB action;
         public void init()
              panel = new BIAP();
              action = new TB(panel);
              action.setLayout(new GridLayout(2,2));     
              cp = getContentPane();
              cp.setLayout(new BorderLayout());
              cp.add(action, "North");
              cp.add(new JScrollPane(panel));
              repaint();
    //******************* BIAP.java*************
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.util.Vector;     
    import java.applet.*;     
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.lang.reflect.Field;
    class BIAP extends JPanel
         public BIA bia;
         public BufferedImage image;
         public double scale, scaleInc;
         public JTextArea jt;
         public BIAP()
              loadImage();
              setBackground(Color.white);
              scale = 1.0;
              scaleInc = 0.01;
              setLayout(null);
              jt = new JTextArea("Welcome");
              jt.setBounds(0,0, 90,30);
              add(jt);     
              repaint();
         protected void paintComponent(Graphics g)
              super.paintComponent(g);
                   Graphics2D g2 = (Graphics2D)g;
              g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                        RenderingHints.VALUE_INTERPOLATION_BICUBIC);
              int w = getWidth();
              int h = getHeight();
              int imageWidth = image.getWidth();
              int imageHeight = image.getHeight();
              int x = (w - imageWidth)/2;
              int y = (h - imageHeight)/2;
              g2.drawImage(image, x, y, this);
         private void loadImage()
              String fileName = "Terragen___Losing_Grip_by_Blackheart6004.jpg";
              try
              URL url = getClass().getResource(fileName);
              System.out.println(url);
              image = ImageIO.read(url);
              catch(MalformedURLException mue)
              System.out.println("url: " + mue.getMessage());
              catch(IOException ioe)
              System.out.println("read: " + ioe.getMessage());
         public Dimension getPreferredSize()
              Dimension d = new Dimension();
              d.width = (int)(scale * image.getWidth());
              d.height = (int)(scale * image.getHeight());
              return d;
         //method used for Zoom Operation
         public void setScale (int inc)
              scale += inc * scaleInc;
              revalidate();
              repaint();
    //************************** TB*********************
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.util.Vector;     
    import java.applet.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class TB extends JPanel
         BIAP panel;
         JButton save = new JButton("Save");
         public TB(BIAP biap)
              panel = biap;
              ActionListener sa = new ActionListener()
                   public void actionPerformed(ActionEvent e)          
                        JButton button = (JButton)e.getSource();
                        if(button == save)
                             //panel.fileSave();
              save.addActionListener(sa);
              add(save);
    }

  • Problem in repaint

    I drawn some rectangles.If one rectangle was clicked,the rectangles below it should move down..but for me,its not repainting.the old location as well as the new location was there when i click the rectangle...
    import javax.swing.JApplet;
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.awt.event.MouseEvent;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Graphics;
    import java.awt.Rectangle;
    import java.awt.Rectangle;
    import java.awt.event.MouseListener;
    import java.util.ArrayList;
    * @author 8563
    public class TestTree extends JApplet
        @Override
        public void init()
            Container con = getContentPane();
            con.setLayout(new BorderLayout());
            setPreferredSize(new Dimension(300, 300));
            JScrollPane scroll = new JScrollPane();
            getContentPane().add(scroll, BorderLayout.CENTER);
            scroll.setViewportView(new ImagePanel());
        private class ImagePanel extends JPanel implements MouseListener {
            ImagePanel image;
            Rectangle rext = new Rectangle(40, 40, 30, 15);
            int[] x = {75, 95, 115, 130};
            int[] width = {15, 15, 15, 15};
            boolean selected1 = false;
            int count;
            Rectangle [] rects;
            Rectangle [] rectangles;
            ArrayList<Rectangle> hlp;
            public ImagePanel()
                prepareData();
                this.addMouseListener(this);
            @Override
            protected void paintComponent(Graphics g)
                Graphics2D g2 = (Graphics2D) g;
                g2.draw(rext);
                drawRect(g2);
            public void prepareData()
                int x = 75;
                int y = 85;
                int w = 20;
                int h = 15;
                hlp = new ArrayList<Rectangle>();
                for (int i = 0; i < 4; i++) {
                    hlp.add(new Rectangle(x, y, w, h));
                    y += 25;
                rectangles = hlp.toArray(new Rectangle[hlp.size()]);
           public void drawRect(Graphics g)
                Graphics2D g2 = (Graphics2D) g;
                for (Rectangle r : rectangles)
                    g2.draw(r);
                    //repaint();
            public void mouseClicked(MouseEvent e)
                Point mse_clk = e.getPoint();
                int count_incr = count+1;
                int y = 150;
                for(int i=count_incr;i<rectangles.length;i++)
                    if(selected1)
                        rectangles.setLocation(rectangles[i].x,rectangles[i].y+20);
    // repaint();
    repaint();
    public void mousePressed(MouseEvent e)
    Point pres_point = e.getPoint();
    for (int i=0;i<rectangles.length;i++)
    if(rectangles[i].contains(pres_point))
    selected1 = true;
    count = i;
    break;
    public void mouseReleased(MouseEvent e)
    public void mouseEntered(MouseEvent e)
    public void mouseExited(MouseEvent e)
    public static void main(String[] args) {
    JApplet applet = new TestTree();
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(applet);
    f.setSize(400, 400);
    f.setLocationRelativeTo(null);
    applet.init();
    f.setVisible(true);

            @Override
            protected void paintComponent(Graphics g)
                // paint the background..
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D) g;
                g2.draw(rext);
                drawRect(g2);
            }

  • HELP!!!! connecting database to JApplet

    I have posted earlier and received help repainting panels on my JApplet. However, my applet doesn't retrieve data from an Access database which is also on the server in the same folder.
    When I run the class as an application on my local pc it works fine but as an applet on the server it doesn't retrieve the data. It doesn't retrieve anything. It doesn't even connect to the driver properly. My code to connect is like so:
    <code>
    //connects to database
    String dataSourceName = "http://fiji.agere.com/indrani/db1.mdb";
    String dbURL = "jdbc:odbc:" + dataSourceName;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }catch(Exception e){System.out.println("Could not connect to driver.");}
    try{   
    Connection con = DriverManager.getConnection(dbURL, "","");
    Statement stmt = con.createStatement();
    ResultSet result = stmt.executeQuery("SELECT Function FROM function_description ORDER BY Function ASC");
    }catch (SQLException e){System.out.println(e.getMessage());}
    </code>
    I put the code in the Init method and in myactionPerformed method.

    I have very limited experience in this area but I have got to make up for a dumb question asked elsewhere by me! So here goes, the datasource name looks wrong. It is in an internet format (HTTP...) rather than a simple file path and name. If this code is running on the actual server that the mdb file is on then I would think that the format would be similar to that of your application code.

  • Adding a Panel to JApplet doesn't work properly

    Hi there,
    I have a class "Editor" extended from JPanel to edit some data. In my JApplet I added a JMenubar with setJMenubar() and registered an ActionListener to the menu items. Everything works fine except the displaying of the EditorPanel after choosing the menu item.
    When I'm adding the Panel in the constructor of the applet it is shown correctly.
    public class EditorApplet extends JApplet implements ActionListener
      public void init()
        setJMenuBar(createJMenuBar());
        Editor e = new Editor();
        getContentPane().add(e); // works perfectly
        e.load(2); // load data into editor
      public void actionPerformed(ActionEvent e)
        if (e.getActionCommand().equals("..."))
          Editor e = new Editor();
          e.loadObjects(1);
          getContentPane().removeAll();
          getContentPane().add(e); // nothing happens!?
          getContentPane().repaint(); // ???
          repaint(); // ???
        }What else needs to be done to display the 'new' Editor?

    Wait. You're adding an ActionEvent to your panel.
    I think you want to do "add(this.e)".

Maybe you are looking for