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

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

  • 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();

  • DragAndDrop question

    hi all,
    somehow, the drop() function in my code below is not being called. anyone has any idea how to get it to work? thanks in advance.
    package ProactNesPN.device.applet;
    import java.util.*;
    import java.awt.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    import java.io.IOException;
    public class DeviceViewApplet extends JFrame
        private JTextArea     txtArea;
        private DeviceMapPane deviceMapPane;
        private DeviceList    policyList;
        // only visible to internal classes
        Vector deviceVector;
        public DeviceViewApplet()
            setTitle("Device Applet");
            setBounds(50, 100, 600, 420);
            addNotify();
            deviceVector = new Vector();
            // toolbar
            JToolBar toolBar = new JToolBar();
            JButton button = null;
            button = new JButton(new ImageIcon("images/uploadup.gif"));
            toolBar.add(button);
            toolBar.addSeparator();
            button = new JButton(new ImageIcon("images/globalup.gif"));
            toolBar.add(button);
            toolBar.addSeparator();
            button = new JButton(new ImageIcon("images/bandwidthcontrolup.gif"));
            toolBar.add(button);
            button = new JButton(new ImageIcon("images/multimediaup.gif"));
            toolBar.add(button);
            toolBar.addSeparator();
            button = new JButton(new ImageIcon("images/greenlightup.gif"));
            toolBar.add(button);
            toolBar.setFloatable(false);
            // device map
            deviceMapPane          = new DeviceMapPane(this);
            JScrollPane scrollPane = new JScrollPane(deviceMapPane);
            // device information
            txtArea = new JTextArea("  Device Information  ", 30, 180);
            // policy basket
            DefaultListModel targetModel = new DefaultListModel();
            targetModel.addElement( "Target Item1");
            targetModel.addElement( "Target Item2");
            policyList = new DeviceList(targetModel);
            Box leftBox = Box.createVerticalBox();
            leftBox.add(txtArea);
            JScrollPane listPane = new JScrollPane(policyList);
            leftBox.add(new JLabel("Policies"));
            leftBox.add(listPane);
            // build the display
            JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftBox, scrollPane);
            JPanel contentPane   = new JPanel();
            contentPane.setLayout(new BorderLayout());
            contentPane.add(toolBar, BorderLayout.NORTH);
            contentPane.add(splitPane, BorderLayout.CENTER);
            getContentPane().add(contentPane);
        public void addDevice(Device dv)
            deviceVector.add(dv);
        public static void main (String[] args)
            DeviceViewApplet applet = new DeviceViewApplet();
            applet.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Device device1 = new Device("Akihabara-edge-1", "cisco", 20, 50);
            Device device2 = new Device("Kyoto-edge-1", "fujitsu", 200, 200);
            Device device3 = new Device("Ueno-edge-1", "extreme", 450, 300);
            applet.addDevice(device1);
            applet.addDevice(device2);
            applet.addDevice(device3);
            applet.repaint();
            applet.setVisible(true);
    class DeviceMapPane extends JPanel implements DragSourceListener, DragGestureListener,
    DropTargetListener, MouseListener
        private DeviceViewApplet applet;
        private ImageIcon routerCisco;
        private ImageIcon routerExtreme;
        private ImageIcon routerFujitsu;
         * enables this component to be a Drag Source
        DragSource dragSource = null;
         * enables this component to be a dropTarget
        DropTarget dropTarget = null;
         * the device selected by the user
        Device     selectedDevice = null;
        public DeviceMapPane(DeviceViewApplet applet)
            this.applet = applet;
            try
                routerCisco   = new ImageIcon("images/routercisco.gif");
                routerExtreme = new ImageIcon("images/routerextreme.gif");
                routerFujitsu = new ImageIcon("images/routerfujitsu.gif");
            catch (Exception e)
                System.out.println("GIF file missing. " + e);
            dropTarget = new DropTarget (this, this);
            dragSource = new DragSource();
            dragSource.createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_MOVE, this);
            addMouseListener(this);
        public void paint(Graphics g)
            paintDevices(g);
        public void paintDevices(Graphics g)
            Device[] devices = null;
            if (applet.deviceVector.size() != 0)
                devices = (Device[]) applet.deviceVector.toArray(new Device[applet.deviceVector.size()]);
            if (devices != null)
                for (int i=0; i < devices.length; i++)
                    Image img = getImage(devices.getVendor());
    g.drawImage(img, devices[i].getX() - 16, devices[i].getY() - 16, this);
    g.setColor(Color.blue);
    g.drawChars(devices[i].getName().toCharArray(), 0, devices[i].getName().length(),
    devices[i].getX() - 30, devices[i].getY() + 30);
    private Image getImage(String vendor)
    if (vendor.equalsIgnoreCase("cisco"))
    return routerCisco.getImage();
    else if (vendor.equalsIgnoreCase("extreme"))
    return routerExtreme.getImage();
    else if (vendor.equalsIgnoreCase("fujitsu"))
    return routerFujitsu.getImage();
    return routerFujitsu.getImage();
    private void selectDevice(Point pt)
    int posX = pt.x;
    int posY = pt.y;
    Device[] devices = null;
    if (applet.deviceVector.size() != 0)
    devices = (Device[]) applet.deviceVector.toArray(new Device[applet.deviceVector.size()]);
    if (devices != null)
    for (int i=0; i< devices.length; i++)
    int dvPosX = devices[i].getX();
    int dvPosY = devices[i].getY();
    if ((posX - 16) <= dvPosX && dvPosX <= (posX + 16))
    if ((posY - 16) <= dvPosY && dvPosY <= (posY + 16))
    selectedDevice = devices[i];
    break;
    else
    selectedDevice = null;
    else
    selectedDevice = null;
    public void dragEnter(DragSourceDragEvent e)
    System.out.println("dragEnter DragSourceEvent - DeviceMapPane");
    public void dragOver(DragSourceDragEvent e)
    public void dragExit(DragSourceEvent e)
    System.out.println("dragExit DragSourceEvent - DeviceMapPane");
    public void dragDropEnd(DragSourceDropEvent e)
    System.out.println("dragDropEnd - DeviceMapPane");
    if ( e.getDropSuccess()){
    System.out.println("drop success");
    //applet.repaint();
    public void dropActionChanged(DragSourceDragEvent e)
    System.out.println("dropActionChanged DragSourceEvent - DeviceMapPane");
    * a drag gesture has been initiated
    public void dragGestureRecognized(DragGestureEvent e)
    System.out.println("dragGestureRecognized");
    //selectDevice( e.getDragOrigin() );
    if (selectedDevice != null)
    System.out.println("drag started");
    // as the name suggests, starts the dragging
    dragSource.startDrag (e, DragSource.DefaultMoveDrop, selectedDevice, this);
    // dragSource.startDrag (e, DragSource.DefaultMoveDrop, getImage(selectedDevice.getVendor()),
    // new Point(0, 0), selectedDevice, this);
    public void dragEnter(DropTargetDragEvent e)
    System.out.println("dragEnter DropTarget - DeviceMapPane");
    //e.acceptDrag (DnDConstants.ACTION_MOVE);
    public void dragOver(DropTargetDragEvent e)
    System.out.println("dragOver DropTarget - DeviceMapPane");
    e.acceptDrag (DnDConstants.ACTION_MOVE);
    public void dragExit(DropTargetEvent e)
    System.out.println("dragExit DropTarget - DeviceMapPane");
    public void drop(DropTargetDropEvent e)
    System.out.println("drop into DeviceMapPane");
    public void dropActionChanged(DropTargetDragEvent e)
    System.out.println("dropActionChanged DropTargetDragEvent - DeviceMapPane");
    public void mousePressed(MouseEvent e)
    System.out.println("mousePressed");
    selectDevice( e.getPoint() );
    public void mouseReleased(MouseEvent e)
    System.out.println("mouseReleased");
    int posX = e.getX();
    int posY = e.getY();
    if (selectedDevice == null || posX < 0 || posY < 0)
    return;
    else
    selectedDevice.setX(posX);
    selectedDevice.setY(posY);
    applet.repaint();
    public void mouseClicked(MouseEvent e) {}
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    class DeviceList extends JList implements DropTargetListener
    * enables this component to be a dropTarget
    DropTarget dropTarget = null;
    public DeviceList()
    super();
    dropTarget = new DropTarget (this, this);
    public DeviceList(DefaultListModel l)
    super(l);
    dropTarget = new DropTarget (this, this);
    public void dragEnter(DropTargetDragEvent e)
    System.out.println("DeviceList - dragEnter DropTarget");
    //e.acceptDrag (DnDConstants.ACTION_MOVE);
    public void dragOver(DropTargetDragEvent e)
    System.out.println("DeviceList - dragOver DropTarget");
    e.acceptDrag (DnDConstants.ACTION_COPY_OR_MOVE);
    public void dragExit(DropTargetEvent e)
    System.out.println("DeviceList - dragExit DropTarget");
    public void drop(DropTargetDropEvent e)
    System.out.println("dropped into DeviceList");
    try
    Transferable transferable = e.getTransferable();
    // we accept only Strings
    if (transferable.isDataFlavorSupported (Device.DEVICE_FLAVOR)){
    e.acceptDrop(DnDConstants.ACTION_MOVE);
    String s = (String)transferable.getTransferData ( Device.DEVICE_FLAVOR);
    addElement( s );
    e.getDropTargetContext().dropComplete(true);
    else{
    e.rejectDrop();
    catch (IOException exception)
    exception.printStackTrace();
    System.err.println( "Exception" + exception.getMessage());
    e.rejectDrop();
    catch (UnsupportedFlavorException ufException )
    ufException.printStackTrace();
    System.err.println( "Exception" + ufException.getMessage());
    e.rejectDrop();
    public void dropActionChanged(DropTargetDragEvent e)
    System.out.println("dropActionChanged");
    public void addElement(Object s)
    (( DefaultListModel )getModel()).addElement (s.toString());
    public void removeElement()
    class Device implements Transferable
    //final public static DataFlavor DEVICE_FLAVOR = new DataFlavor(Device.class, "Device Type");
    final public static DataFlavor DEVICE_FLAVOR = new DataFlavor(Device.class, DataFlavor.javaJVMLocalObjectMimeType);
    static DataFlavor[] flavors = { DEVICE_FLAVOR };
    private String name;
    private String vendor;
    private int x;
    private int y;
    public Device(String name, String vendor, int x, int y)
    this.name = name;
    this.vendor = vendor;
    this.x = x;
    this.y = y;
    public String getName()
    return this.name;
    public String getVendor()
    return this.vendor;
    public int getX()
    return this.x;
    public int getY()
    return this.y;
    public void setX(int x)
    this.x = x;
    public void setY(int y)
    this.y = y;
    public Object getTransferData(DataFlavor flavor)
    throws UnsupportedFlavorException, IOException
    System.out.println("transferable - getTransferData");
    if (flavor.equals(DEVICE_FLAVOR))
    return this;
    else throw new UnsupportedFlavorException(flavor);
    public DataFlavor[] getTransferDataFlavors()
    System.out.println("transferable - getTransferDataFlavors");
    return flavors;
    public boolean isDataFlavorSupported(DataFlavor flavor)
    System.out.println("transferable - isDataFlavorSupported");
    if (flavor.equals(DEVICE_FLAVOR))
    return true;
    return false;

    My transferable object needs to be serializable! I have solved the problem, thanks.

  • Change language during Runtime

    Hey,
    i have following problem: I use Resourcebundles to internationalize my Java Applet. Now i want to add two Buttons where the user can change the language.
    I changed my i18n class to the following code:
    public class Messages
         private static final String          BUNDLE_NAME     = "de.mypackage.core.messages";     //$NON-NLS-1$
         private static ResourceBundle     resBundle     = null;
         static
              try
                   resBundle = ResourceBundle.getBundle(BUNDLE_NAME);
              } catch (MissingResourceException exc)
                   System.out.println("Can not find the ressource bundle for i18n.");
         static void setLocale(Locale locale)
              resBundle = ResourceBundle.getBundle(BUNDLE_NAME, locale);
         public static String getString(String key)
              try
                   return resBundle.getString(key);
              } catch (MissingResourceException e)
                   return '!' + key + '!';
    }When pressing the "english" button following code is executed:
    Messages.setLocale(Locale.ENGLISH);
    applet.repaint();
    applet.validate();But the language doesn�t change :-( What can i do?
    Thanks alot

    But the language doesn�t change :-( What can i do?I once did it this way: the problem is that all your Components already
    had their text set (e.g. JButton.setText(...)) and all those components are
    not aware of the fact that you changed your Locale so they don't do
    anything.
    Therefore I extended all these Swing classes and added an interface:
    LanguageListener which gets invoked when a Locale has changed.
    The Language listener just extends the PropertyChangeListener.
    When the method is invoked the Component sets its text again according
    to the now current Locale. It's a bit of work but it pays off ;-)
    kind regards,
    Jos

  • Need help/advice with tic tac toe game

    Hello all. I am working on a tic tac toe game. I was able to program the first 4 moves fine, but ame having trouble with moves 5 and 6 for reasons that are unknown to me. Everything complies fine, its just that the move is displayed int the wrong space (B1) instead of in B2 or B3. Also the move that is supposed to be in A1 disapppears when B2 or B3 is clicked. Also, I need advice as to how to keep the prior moves from being over written.
    At this point I ahve gone over the code on-screen, printed it out, and stared at my drawings... and I'm not having any luck. I'm sure its a small, stupid thing that I'm missing, that anyone else would easily catch. Once again, thx for all your help.
    import java.awt.event.*;
    import java.awt.*;
    import java.applet.*;
    public class game3 extends Applet implements MouseListener{
         String move = "";
         boolean player1 = true;
         String gameBoard[][] = new String [3][3];
    public void spaceA1(Graphics g){ // MOVE IS A1
         if(gameBoard[0][0] == "X")
              g.drawString("X",65,65);
         if(gameBoard[0][0] == "O")
              g.drawString("O",65,65);
    public void spaceA2(Graphics g){ // MOVE IS A2
         if(gameBoard[0][1] == "X")
              g.drawString("X",95,65);
         if(gameBoard[0][1] == "O")
              g.drawString("O",95,65);                         
    public void spaceA3(Graphics g){ // MOVE IS A3               
         if(gameBoard[0][2] == "X")
              g.drawString("X",125,65);
         if(gameBoard[0][2] == "O")
              g.drawString("O",125,65);
    public void spaceB1(Graphics g){ // MOVE IS B1
         if(gameBoard[1][0] == "X")
              g.drawString("X",65,95);
         if(gameBoard[1][0] == "O")
              g.drawString("O",65,95);                    
    public void spaceB2(Graphics g){ // MOVE IS B2
         if(gameBoard[1][1] == "X")
              g.drawString("X",95,95);
         if(gameBoard[1][1] == "O")
              g.drawString("O",95,95);
    public void spaceB3(Graphics g){ // MOVE IS B3
         if(gameBoard[1][2] == "X")
              g.drawString("X",125,95);
         if(gameBoard[1][2] == "O")
              g.drawString("O",125,95);
    public void spaceC1(Graphics g){ // MOVE IS C1
         if(gameBoard[2][0] == "X")
              g.drawString("X",65,125);
         if(gameBoard[2][0] == "O")     
              g.drawString("O",65,125);     
    public void spaceC2(Graphics g){ // MOVE IS C2
         if(gameBoard[2][1] == "X")
              g.drawString("X",95,125);
         if(gameBoard[2][1] == "O")
              g.drawString("O",95,125);
    public void spaceC3(Graphics g){ // MOVE IS C3
         if(gameBoard[2][2] == "X")
              g.drawString("X",125,125);
         if(gameBoard[2][2] == "O")
              g.drawString("O",125,125);
    public void init(){
         addMouseListener(this);
         public void paint(Graphics g){
              g.drawString("    1       2       3", 50,45);
              g.drawString("A",40,70);
              g.drawString("B",40,100);
              g.drawString("C",40,130);
              // first row of boxes
              g.drawRect(50,50,30,30);
              g.drawRect(80,50,30,30);
              g.drawRect(110,50,30,30);
              // second row of boxes
              g.drawRect(50,80,30,30);
              g.drawRect(80,80,30,30);
              g.drawRect(110,80,30,30);
              // third row of boxes
              g.drawRect(50,110,30,30);
              g.drawRect(80,110,30,30);
              g.drawRect(110,110,30,30);
              if(move == "A1"){
                   spaceA2(g);
                   spaceA3(g);
                   spaceB1(g);
                   spaceB2(g);
                   spaceB3(g);
                   spaceC1(g);
                   spaceC2(g);
                   spaceC3(g);
                   if(player1){
                   gameBoard[0][0] = "X";
                   g.drawString("X",65,65);
                   player1 = false;
                   return;
                   else
                   if(!player1){
                   gameBoard[0][0] = "O";
                   g.drawString("O",65,65);
                   player1 = true;
                   return;
              } // end of A1
              else
              if(move == "A2"){
                   spaceA1(g);
                   spaceA3(g);
                   spaceB1(g);
                   spaceB2(g);
                   spaceB3(g);
                   spaceC1(g);
                   spaceC2(g);
                   spaceC3(g);
                   if(player1){
                   gameBoard[0][1] = "X";     
                   g.drawString("X",95,65);
                   player1 = false;
                   return;
                   else
                   if(!player1){
                   gameBoard[0][1] = "O";
                   g.drawString("O",95,65);
                   player1 = true;
                   return;
              } // end of A2
              else
              if(move == "A3"){
                   spaceA1(g);
                   spaceA2(g);
                   spaceB1(g);
                   spaceB2(g);
                   spaceB3(g);
                   spaceC1(g);
                   spaceC2(g);
                   spaceC3(g);
                   if(player1){
                   gameBoard[0][2] = "X";
                   g.drawString("X",125,65);
                   player1 = false;
                   return;
                   else
                   if(!player1){
                   gameBoard[0][2] = "O";
                   g.drawString("O",125,65);
                   player1 = true;
                   return;
              } // end of A3
              else
              if(move == "B1")
                   spaceA1(g);
                   spaceA2(g);
                   spaceA3(g);
                   spaceB2(g);
                   spaceB3(g);
                   spaceC1(g);
                   spaceC2(g);
                   spaceC3(g);
                   if(player1){
                   gameBoard[1][0] = "X";
                   g.drawString("X",65,95);
                   player1 = false;
                   return;
                   else
                   if(!player1){
                   gameBoard[1][0] = "O";
                   g.drawString("O",65,95);
                   player1 = true;
                   return;
              } // end of B1
              else
              if(move == "B2"){
                   spaceA1(g);
                   spaceA2(g);
                   spaceA3(g);
                   spaceB1(g);
                   spaceB3(g);
                   spaceC1(g);
                   spaceC2(g);
                   spaceC3(g);
                   if(player1){
                   gameBoard[1][1] = "X";
                   g.drawString("X",95,95);
                   player1 = false;
                   return;
                   else
                   if(!player1){
                   gameBoard[1][1] = "O";
                   g.drawString("O",95,95);
                   player1 = true;
                   return;
              } // end of B2
              else
              if(move == "B3"){
                   spaceA1(g);
                   spaceA2(g);
                   spaceA3(g);
                   spaceB1(g);
                   spaceB2(g);
                   spaceC1(g);
                   spaceC2(g);
                   spaceC3(g);
                   if(player1){
                   gameBoard[1][2] = "X";
                   g.drawString("X",125,95);
                   player1 = false;
                   return;
                   else
                   if(!player1){
                   gameBoard[1][2] = "O";
                   g.drawString("O",125,95);
                   player1 = true;
                   return;
              }// end of B3
         }// end of graphics
         public void mouseReleased(MouseEvent me){}
         public void mousePressed(MouseEvent me){}
         public void mouseDragged(MouseEvent me){}
         public void mouseEntered(MouseEvent me){}
         public void mouseExited(MouseEvent me){}
         public void mouseClicked(MouseEvent me){
              int x = me.getX();
              int y = me.getY();
              if((x >=51) && (x<= 79) && (y >= 51) && (y <= 79)) //MOVE IS A1
                   move = "A1";
              else
              if((x >=81) && (x<=109) && (y >=51) && (y <= 79))  //MOVE IS A2
                   move = "A2";
              else
              if((x >=111) && (x<=139) && (y >=51) && (y <= 79))  //MOVE IS A3
                   move = "A3";
              else
              if((x >=51) && (x<= 79) && (y >= 81) && (y <= 109))  //MOVE IS B1
                   move = "B1";
              else
              if((x >=81) && (x<=109) && (y >=81) && (y <= 109))  //MOVE IS B2
                   move = "B2";
              else
              if((x >=111) && (x<=139) && (y >=81) && (y <= 109))  //MOVE IS B3
                   move = "B3";
              repaint();
    //<applet code = "game3.class" height =300 width=300> </applet>     

    writing a tic-tac-toe is harder than it sounds.. i wrote one last year in my computer science class.. i have it on my website, if you want to look at code. i wrote it in c++, but the logic is all that matters :)
    btw-last year, i wasnt too good of an OOP programmer, so the program is procedurely written. heres the url:
    http://www.angelfire.com/blues/smb
    also, to tell if a box is already taken, you can just add an if statement:   if ( gameBoard[selX][selY] == null )  //not taken, fill box:many people resort to a boolean matrix of the same idea, but with booleans that store which boxes are taken. i prefer the way above, saves code, memory, and makes it more understandable.
    hope it helps.

  • How do this problem

    Hi all. I'm stuck on this one problem at my school... Yes, its for school, i'll admit it. Heh.
    Here is the problem:
    "Write an applet that displays a line graph that plots temperature changes for eight days. Create a TextField and Label for each of the eight temperatures that the user enters. Use a prompt above the TextFields telling the user to enter temperatures and to press the Enter key in the eighth TextField when finished. When the user presses the enter key in the last TextField, displays the graph.
    To create a graph, drawa horizizontol baseline on the screen with the days numbered one degree of temperature, draw lines from point to point above the horizontol baseline reflecting the temperature changes from day to say."
    Right now I have to go too another class. Tommorow I'll try it out again from scratch. But so far, all I've been getting is tons of errors, so I am going to start over. Can someone help me out here? What do I use? drawString() ? How would I use that effiecantly?
    I also have another problem that is alike. "Write an applet that displays a horizontal bar chat for company bloood drive. The user enters a number of pints of bloods donated by employees in each of five departments. There should be a TextField and Label for each department donor court. When the user presses the enter key in the last textfield, displays the chart. Create a vertical baseline; then create one horizontal line for each department."
    This one I think would be close to the first one. I'm guessing if someone helps me with one of them I could do the other. I'm not positive how this would work though. I think there is more then just drawString? I'm not sure how it would work efficantly, and how when I hit enter in the last textfield, it would do it and display it.. I'm guessing using a paint() as well?
    I'll try it tommorow, if you don't wanna help yet thats okay, but if so, It would be greatful. (Throws duke dollers around, rofl:)) But thanks anyways!

    Ok.. Now I having a paint problem. Here is the coding.
    //Class Mr. I
    //Filename: Name
    //By: Chris Valleriani
    //April 8th, 2003
    //This will display a bar graph. Input 5 numbers to complete it.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Graph1 extends Applet implements ActionListener
         Button pressMe = new Button("Output Chart!");
         //Labels and textfields
         Label myname1 = new Label("Day 1:");
         TextField day1 = new TextField(10);
         Label myname2 = new Label("Day 2:");
         TextField day2 = new TextField(10);
         Label myname3 = new Label("Day 3:");
         TextField day3 = new TextField(10);
         Label myname4 = new Label("Day 4:");
         TextField day4 = new TextField(10);
         Label myname5 = new Label("Day 5:");
         TextField day5 = new TextField(10);
         Color myColor = Color.red; // added variable to store color
         public void paint(Graphics g)
              g.drawLine(50,100,50,200);
              g.setColor( myColor ); // set color
         public void init()
              add(myname1);
              add(day1);
              add(myname2);
              add(day2);
              add(myname3);
              add(day3);
              add(myname4);
              add(day4);
              add(myname5);
              add(day5);
              add(pressMe);
              pressMe.addActionListener(this);
         public void actionPerformed(ActionEvent thisEvent)
              Graphics d = getGraphics();
              //Changing the TextField to a integer.
              int x1 = (new Integer(day1.getText())).intValue();
              int x2 = (new Integer(day2.getText())).intValue();
              int x3 = (new Integer(day3.getText())).intValue();
              int x4 = (new Integer(day4.getText())).intValue();
              int x5 = (new Integer(day5.getText())).intValue();
              //Whatever you put in the TextField, will output here into lines.
              g.drawLine(x1,110,50,110);
              g.drawLine(x2,130,50,130);
              g.drawLine(x3,150,50,150);
              g.drawLine(x4,170,50,170);
              g.drawLine(x5,190,50,190);
              repaint(); // repaint applet
              validate();
    It SHOULD work. But it doesnt display the lines when you click the button. Is there any way to do it? Like hitting the enter key?
    It seems fine other then that..

  • Enemy cant be hit?!?!?!

    My problem is that when the shot fired by the player "hits" the enemy, the enemy will not go away. I am making a Galaga like game and it is really confusing me as to why this isnt working. Any advice would be awesome!
    He is my code:
    //Main.java
    import java.applet.*;
    import java.awt.*;
    import java.util.*;
    public class Main extends Applet implements Runnable
         private Thread th;
         private Player player;
         private Shoot[] shot;
         private Enemy enemy;
         private int appletsize_x = 300;
         private int appletsize_y = 300;
         int enemySize = 15;
         boolean enemyHit;
         //Speed constants
         private int shotSpeed = -2;
         private int playerRightSpeed = 2;
         private int playerLeftSpeed = -2;
         private int enemySpeed = 1;
         //Player flags
         private boolean playerLeft;
         private boolean playerRight;
         //double buffering
         private Image dbImage;
         private Graphics dbg;
         public void init()
              player = new Player(150,280);
              shot = new Shoot[7]; //allows 7 shots to be fired at once
              enemy = new Enemy(150,125);
              enemy.setEnemySize(enemySize);
              setBackground(Color.black);
         public void start()
              th = new Thread(this);
              th.start();
         public void stop()
              th.stop();
         public void destroy()
              th.stop();
         public void run()
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              while(true)
                   //test for number of shots
                   for(int i=0; i<shot.length; i++)
                        if (shot[i] != null)
                             shot.moveShot(shotSpeed);
    //******************************************************************************************************I believe the probelm is here!!!********************************
                             if((shot[i].getX_Pos() == (enemy.getX_Pos()+20)) && (shot[i].getY_Pos() == (enemy.getY_Pos()+20)))
                             enemy.setEnemySize(0);
                             repaint();
                             shot[i] = null;
                             enemyHit = true;
                             if(shot[i].getY_Pos() < 0)
                                  shot[i] = null;
                             }//end else if
                        }//end if
                   }//end for
                   //new enemies/targets
                   if(enemyHit == false)
                        if (enemy.getX_Pos() > appletsize_x - enemySize)
                        // Change direction of enemy movement
                        enemySpeed = -1;
                        // enemy is bounced if its x - position reaches the left border of the applet
                        else if (enemy.getX_Pos() < 0)
                        // Change direction of enemy movement
                        enemySpeed = +1;
                        try
                             Thread.sleep(5);
                             enemy.moveEnemy(enemySpeed);
                        catch(Exception ex)
                        repaint();
                   if(playerLeft)
                        player.moveX_Pos(playerLeftSpeed);
                   if(playerRight)
                        player.moveX_Pos(playerRightSpeed);
                   //repaint applet
                   repaint();
                   try
                        Thread.sleep(10);
                   catch (InterruptedException ex)
                        //do nothing
                   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         public boolean keyDown(Event e, int key)
              //Left key- moves player left
              if (key == Event.LEFT)
                   playerLeft = true;
              //Right key - moves player right
              else if (key == Event.RIGHT)
                   playerRight = true;
              //Space bar - fires shot
              else if(key == 32)
                             // generate new shot and add it to shots array
                             for(int i=0; i<shot.length; i++)
                                  if(shot[i] == null)
                                       shot[i] = player.getShot();
                                       break;
              return true;
         }//end of keyDown
         //if fire is not being pressed do this
         public boolean keyUp(Event e, int key)
              if(key == Event.LEFT)
                   playerLeft = false;
              else if(key == Event.RIGHT)
                   playerRight = false;
              return true;
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
         }//end of update
         public void paint(Graphics g)
              player.drawPlayer(g);
              enemy.drawEnemy(g);
              //draw shots
              for(int i=0; i<shot.length;i++)
                   if(shot[i] != null)
                   shot[i].drawShot(g);
                   }//end of inner if
              }//end of for
         }//end of paint
    }//end of class

    Here is the main class again and the enemy class. Please help!
    //Main.java
    import java.applet.*;
    import java.awt.*;
    import java.util.*;
    public class Main extends Applet implements Runnable
         private Thread th;
         private Player player;
         private Shoot[] shot;
         private Enemy enemy;
         private int appletsize_x = 300;
         private int appletsize_y = 300;
         int enemySize = 15;
         boolean enemyHit;
         //Speed constants
         private int shotSpeed = -2;
         private int playerRightSpeed = 2;
         private int playerLeftSpeed = -2;
         private int enemySpeed = 1;
         //Player flags
         private boolean playerLeft;
         private boolean playerRight;
         //double buffering
         private Image dbImage;
         private Graphics dbg;
         public void init()
              player = new Player(150,280);
              shot = new Shoot[7];
              enemy = new Enemy(150,125);
              enemy.setEnemySize(enemySize);
              setBackground(Color.black);
         public void start()
              th = new Thread(this);
              th.start();
         public void stop()
              th.stop();
         public void destroy()
              th.stop();
         public void run()
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              while(true)
                   //test for number of shots
                   for(int i=0; i<shot.length; i++)
                        if (shot[i] != null)
                             shot.moveShot(shotSpeed);
    //*********************I believe the probelm is here!!!********************************
                             if((shot[i].getX_Pos() == (enemy.getX_Pos()+100)) && (shot[i].getY_Pos() == (enemy.getX_Pos()-100))
                                       && (shot[i].getY_Pos() == (enemy.getY_Pos()-100)) && (shot[i].getY_Pos() == (enemy.getY_Pos()+100)))
                             //enemy.setEnemySize(0);
                             repaint();
                             shot[i] = null;
                             enemyHit = true;
                             if(shot[i].getY_Pos() < 0)
                                  shot[i] = null;
                             }//end else if
                        }//end if
                   }//end for
                   //new enemies/targets
                   if(enemyHit == false)
                        if (enemy.getX_Pos() > appletsize_x - enemySize)
                        // Change direction of enemy movement
                        enemySpeed = -1;
                        // enemy is bounced if its x - position reaches the left border of the applet
                        else if (enemy.getX_Pos() < 0)
                        // Change direction of enemy movement
                        enemySpeed = +1;
                        try
                             Thread.sleep(5);
                             enemy.moveEnemy(enemySpeed);
                        catch(Exception ex)
                        repaint();
                   if(playerLeft)
                        player.moveX_Pos(playerLeftSpeed);
                   if(playerRight)
                        player.moveX_Pos(playerRightSpeed);
                   //repaint applet
                   repaint();
                   try
                        Thread.sleep(10);
                   catch (InterruptedException ex)
                        //do nothing
                   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         public boolean keyDown(Event e, int key)
              //Left key- moves player left
              if (key == Event.LEFT)
                   playerLeft = true;
              //Right key - moves player right
              else if (key == Event.RIGHT)
                   playerRight = true;
              //Space bar - fires shot
              else if(key == 32)
                             // generate new shot and add it to shots array
                             for(int i=0; i<shot.length; i++)
                                  if(shot[i] == null)
                                       shot[i] = player.getShot();
                                       break;
              return true;
         }//end of keyDown
         //if fire is not being pressed do this
         public boolean keyUp(Event e, int key)
              if(key == Event.LEFT)
                   playerLeft = false;
              else if(key == Event.RIGHT)
                   playerRight = false;
              return true;
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
         }//end of update
         public void paint(Graphics g)
              player.drawPlayer(g);
              if(enemyHit == false)
              enemy.drawEnemy(g, enemyHit);
              //draw shots
              for(int i=0; i<shot.length;i++)
                   if(shot[i] != null)
                   shot[i].drawShot(g);
                   }//end of inner if
              }//end of for
         }//end of paint
    }//end of class
    Here is the Enemy class//Enemy.java
    import java.awt.*;
    import java.util.*;
    public class Enemy
         private int x_pos;
         private int y_pos;
         private int radius;
         private int appletsize_x = 300;
         private int appletsize_y = 300;
         private int[] size = {10,15,12,8,9};
         //Constructor
         public Enemy(int x, int y)
              x_pos = x;
              y_pos = y;
         //Set the enemys size
         public void setEnemySize(int enemySize)
              radius = enemySize;
         //move the enemy left and right
         public void moveEnemy(int speed)
              x_pos += speed;
         //gets the y cords of the enemy
         public int getY_Pos()
              return y_pos;
         //gets the x cords of the enemy
         public int getX_Pos()
              return x_pos;
         //draw the enemy
         public void drawEnemy(Graphics g, boolean hit)
              if(hit == false)
                   g.setColor(Color.white);
                   g.fillOval(x_pos, y_pos, radius, radius);
    }//close class                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Applet repainting error in IE 5.5 using the scrollbars

    I've created a real straight forward applet using swing components to test out this error. It consists of a couple of JButtons & JLabels added to a JPanel that's the JPanel is added to the ContentPane. I'm using the Java Plug-in 1.3 on a Windows 2000 box using IE 5.5. When I view my applet everything is just fine. But when I'm using the browser scrollbars to view the rest of my applet and try to scroll down, the applet controls and everything within the applet does not get repainted properly onto the screen. Everything in the applet gets painted on top of their old controls a couple of pixels off making it impossible to use. When I scroll to the bottom and top of the page the applet repaints just fine, but it's when I'm scrolling in the middle of the page is where the applet can not repaint properly. I have tested this in Netscape 6.0 and everything works just fine. I'mnot sure what could be causing this but maybe one of you have cameacross this problem before and could help out.
    thanks,
    Peter Landis.

    Here's the code:
    import java.awt.*;
    import javax.swing.*;
    public class TestRepaint extends JApplet
    public void init()
         Container contentPane = getContentPane();
         JPanel panel = new JPanel();
    panel.setBackground(Color.lightGray);
    controls(panel);
         // Grid
         contentPane.add(panel);
    public void controls(JPanel p)
    JLabel imagelabel = new JLabel();
    JLabel imagelabel2 = new JLabel();
    // Create some labels
    JLabel label_1 = new JLabel("TEST 1");
    JLabel label_2 = new JLabel("TEST 2");
    JLabel label_3 = new JLabel("TEST 3");
    JLabel label_4 = new JLabel("TEST 4");
    JLabel label_5 = new JLabel("TEST 5");
    JLabel label_6 = new JLabel("TEST 6");
    JLabel label_7 = new JLabel("TEST 7");
    setLabelControl(label_1);
    setLabelControl(label_2);
    setLabelControl(label_3);
    setLabelControl(label_4);
    setLabelControl(label_5);
    setLabelControl(label_6);
    setLabelControl(label_7);
    // Buttons
    JButton b1 = new JButton("Button 1");
    JButton b2 = new JButton("Button 2");
    JButton b3 = new JButton("Button 3");
    JButton b4 = new JButton("Button 4");
    JButton b5 = new JButton("Button 5");
    JButton b6 = new JButton("Button 6");
    JButton b7 = new JButton("Button 7");
    setButtonControl(b1);
    setButtonControl(b2);
    setButtonControl(b3);
    setButtonControl(b4);
    setButtonControl(b5);
    setButtonControl(b6);
    setButtonControl(b7);
    // Layout
         GridBagLayout gridbag = new GridBagLayout();
         GridBagConstraints c = new GridBagConstraints();
    p.setLayout(gridbag);
    c.anchor = GridBagConstraints.WEST;
         c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.gridwidth = 1;
    // Note Inset is (Top, Left, Bottom, Right);
    c.insets = new Insets(0,5,20,0);
         p.add(label_3,c);
         c.insets = new Insets(0,5,20,1);
    p.add(b3,c);
    c.insets = new Insets(0,5,20,0);
         p.add(label_4,c);
    c.gridwidth = GridBagConstraints.REMAINDER;
         c.insets = new Insets(0,5,20,1);
    p.add(b4,c);
    c.gridwidth = 1;
    c.insets = new Insets(0,5,20,0);
         p.add(label_5,c);
         c.insets = new Insets(0,5,20,1);
    p.add(b5,c);
    c.insets = new Insets(0,5,20,0);
         p.add(label_6,c);
    c.gridwidth = GridBagConstraints.REMAINDER;
         c.insets = new Insets(0,5,20,1);
    p.add(b6,c);
    public void setButtonControl(JButton button)
              button.setBackground(Color.white);
    void setLabelControl(JLabel l)
              l.setFont(new Font("Helvetica", Font.BOLD, 14) );
    l.setForeground(Color.black);
    ||||||||||||||||||||| HTML CODE |||||||||||||||||||
    <title>Test</title>
    <hr>
    <!--"CONVERTED_APPLET"-->
    <!-- CONVERTER VERSION 1.3 -->
    <SCRIPT LANGUAGE="JavaScript"><!--
    var info = navigator.userAgent; var ns = false;
    var ie = (info.indexOf("MSIE") > 0 && info.indexOf("Win") > 0 && info.indexOf("Windows 3.1") < 0);
    //--></SCRIPT>
    <COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!--
    var ns = (navigator.appName.indexOf("Netscape") >= 0 && ((info.indexOf("Win") > 0 && info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0)));
    //--></SCRIPT></COMMENT>
    <SCRIPT LANGUAGE="JavaScript"><!--
    if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 500 HEIGHT = 425 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"><NOEMBED><XMP>');
    else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.3" CODE = "TestRepaint.class" WIDTH = 500 HEIGHT = 425 scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED><XMP>');
    //--></SCRIPT>
    <APPLET CODE = "TestRepaint.class" WIDTH = 500 HEIGHT = 425></XMP>
    <PARAM NAME = CODE VALUE = "TestRepaint.class" >
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    <PARAM NAME="scriptable" VALUE="false">
    </APPLET>
    </NOEMBED></EMBED></OBJECT>
    <!--
    <APPLET CODE = "TestRepaint.class" WIDTH = 500 HEIGHT = 425>
    </APPLET>
    -->
    <!--"END_CONVERTED_APPLET"-->
    <hr>

  • Applet Painting and Repainting

    I have two issues that I think to be related and hope that someone may be able to shed some light on this. I have a problem with an applet that is running within a JSP page. At initial loading, the applet randomly displays with a blank page. If I reload the jsp page from the browser the applet will recover and display appropriately. This happens on both Internet Exploder and Firefox browsers.
    I also have a problem with Components within the applet that, I hope, are related. I have a JTable component that, when I make changes to it, it manages to refresh, but not completely. Some of the data that has changed doesn't refresh but the rest of it does. Again, if I refresh the applet pane the value restore to what is expected.
    I have a repaint call in place at each instance, but that is not working. Are there any suggestions or maybe something else I can try to get this to work as expected. I am fairly inexperienced with applets so any advise and detail would be greatly appreciated.

    You probably can't do this with threads. Rule #1 of threading is that you cannot determine the order of execution, and you basically have no control over this. If you need the images and sound to be displayed sequentially, then by all means download them or load them with separate threads. But you must display them in the same thread to get them displayed sequentially.
    Alan

  • How to implement a repaint when the IE window  is max or min  in a applet?

    Hi!!
    I already did a applet......and it has a button to print the content....when i press the print buttom�.appears a dialog box about that the �Printing will start to print� �OK��Cancel�, I press the yes button and after appears others dialog box about page configuration and all it is ok��.but in the while that are open the others dialogs box�. part the first dialog box remains there (ie the part of dialog box that was showed over the applet of the a dialog the �Printing will start to print� �OK��Cancel� follows there)�..
    I think that I need a repaint of my applet or something like that��.but I don`t know where and how to do it�..
    Also�..when I minimize the window of IE�.and after restore it I can see only part of my applet�.ie�..the part that I hide when I minimized....and after I maximed looks in blank...:(
    Somebody has some ideas or suggestions please?
    Thanks
    Mary

    Hi there,
    thank you for the reply. The thing is not having 2 sessions for one user, but to have 2 sessions for 2 users. Here is the deal: The main Website works with one layout, the links work with other layouts - all layouts are controlled by the user parameter. Image you at the Volkswagen website and want to visit the Audi (subsidiary of Volkswagen) website. Just for fun, image that the two websites run in the same environment and sometimes the share resources. To access the Audi resources you need to login as a Audi user. This causes the layout to be Audi specific. After having had a fast look at the Audi website you decide to close the window. All the time you had your Volkswagen window open in the background. Now, if you want to explorer the Volkswagen website, the user is set to Audi, and therefore all the Volkswagen pages will be shown in Audi layout ....

  • Applet won't repaint itself

    i have an applet that contains a jtexatrea 3 buttons and a jlabel.
    when i start it everuthing is just fine.
    however, my applet is supposed to open a file form the local filesystem (so it is signed) and after i click OK in the choose file dialog, my applet keeps the image of the dialog.
    what do i have to do in order to solve this ?
    p.s. and the same issue occurs when i minimiza the browswer and maximize it again. it just won't repaint.

    A potential solution occurred to me right after I posted, and I think it may be working. (Can't tell for sure until search engine cache's updated with this change.) Basically I expanded the .jar archive name:
    <script type='text/javascript'>
    <!--
    applet_fu.run(
      {'width':'850','height':'690'},
        'archive':'http://r0k.us/graphics/SIHwheel.jar',
        'code':'SIHwheel.class',
      '1.4.2',
      'Get Java for free at http://java.com/ '
    -->
    </script>Before the change, the archive line simply referenced 'SIHwheel.jar'.
    The one downside to this, assuming it works, is that I'll need two versions of the page. A local one on my hard drive for when I want to test before deploying, and the networked version with the full URL. That's a worthwhile trade-off, though.
    Edited by: RichF on Nov 27, 2010 10:39 AM
    PS: the link in first post still fails, but it seems to be accessing yesterday's version of the page (date on bottom). Also I note that the HTML for that Google-translated page and Bing's cache page contain:
    <base href=http://www.r0k.us/graphics/SIHwheel.html />That works well for accessing all the locally-referenced images on the page, but for some reason fails to find the .jar file without a complete URL. The [url http://r0k.us/graphics/applet-fu.js]applet-fu.js script does not appearing to be adorning the archive line in any way.

  • Applet: repaint() causing infinite loop

    I'm developing an applet that draws a linegraph. The user can select which lines of points will be drawn in the applet using checkboxes. I have a separate function as an Itemlistener for the checkboxes, and I call repaint at the end of the itemStateChanged function. For some reason, once the itemlistener has seen one event, the applet gets stuck in a loop, and paint is continually run over and over again. This makes the applet useless as the user can't enter any input since the applet is continually being redrawn. I only want paint to be called once from a repaint() call. I'm not using any loops anywere in my program. Any suggestions?

    ItemListeners tend to throw lots of events when actually only one has happened.
    The solution i use:
    remember the old satus. when an event happens first check if the status has changed, if not do nothing.

  • Repaint() an applet from a swing applet, why does this code not work?

    below are three files that work as planned except for the call to repaint(). This is envoked when a button is hit in one applet and it should repaint another applet. I opened them up in a html file that simply runs both applets. If you could see why the repaint doesn't work I'd love to know. good luck.
    //speech1
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    //java extension packages
    import javax.swing.*;
    public class speechapp1 extends JApplet implements ActionListener{
    // setting up Buttons and Drop down menus
    char a[];
    Choice choicebutton;
    JLabel resultLabel;
    JTextField result;
    JLabel enterLabel;
    JTextField enter;
    JButton pushButton;
    TreeTest PicW;
    // setting up applets G.U.I
    public void init(){
    // Get content pane and set it's layout to FlowLayout
    Container container = getContentPane();
    container.setLayout( new FlowLayout() );
    // initialise buttons and shit
    a = new char[30];
    choicebutton = new Choice();
    enterLabel = new JLabel("Test");
    enter = new JTextField(30);
    resultLabel= new JLabel("speech label");
    result = new JTextField(30);
    result.setEditable(false);
    // Add items to Choice Button
    choicebutton.addItem("abc");
    choicebutton.addItem("def");
    choicebutton.addItem("ghi");
    choicebutton.addItem("jkl");
    pushButton = new JButton("Click to continue");
    // Add new Tree from file TreeTest.java
    PicW = new TreeTest();
    // Add buttons to container.
    container.add(resultLabel);
    container.add(result);
    container.add(enterLabel);
    System.out.println("");
    container.add(choicebutton);
    System.out.println("");
    container.add(pushButton);
    pushButton.addActionListener(this);
    //choicebutton.addActionListener( this );
    // Set the text in result;
    result.setText("Hello");
    //public void paint(Graphics gg){
    // result.setText("Hello");
    public void actionPerformed(ActionEvent event){
    // continue when action performed on pushButton
    String searchKey = event.getActionCommand();
    System.out.println("");
    if (choicebutton.getSelectedItem().equals("abc"))
    PicW.getPicWeight(1);
    if (choicebutton.getSelectedItem().equals("def"))
    PicW.getPicWeight(2);
    if (choicebutton.getSelectedItem().equals("ghi"))
    PicW.getPicWeight(3);
    if (choicebutton.getSelectedItem().equals("jkl"))
    PicW.getPicWeight(4);
    System.out.println("repainting from actionPerformed method()");
    PicW.repaint();
    import java.applet.Applet;
    import java.awt.*;
    import java.util.*;
    public class TreeTest extends Applet{
    Tree BackgroundImageTree;
    Tree PlayerImageTree;
    Image snow,baby;
    int weight;
    public void getPicWeight(int w){
    weight = w;
    System.out.println("the new weight has been set at: "+weight);
    this.repaint();
    public void init()
    // initialising trees for backgound images and player images
    BackgroundImageTree = new Tree();
    PlayerImageTree = new Tree();
    // initialising images and correcting size of images to correctly fit the screen
    snow = getImage(getDocumentBase(),"snow.gif");
    baby = getImage(getDocumentBase(),"baby.gif");
    // inserting images into correct tree structure
    System.out.println("inserting images into tree: ");
    // inserting background images into tree structure
    BackgroundImageTree.insertImage(1,snow);
    // inserting players into tree structure
    PlayerImageTree.insertImage(1,baby);
    public void paint(Graphics g){
    System.out.println("Searching for selected Image");
    if((BackgroundImageTree.inorderTraversal(1)==null)&&(PlayerImageTree.inorderTraversal(1)==null)){
    System.out.println("There is no tree with the selected value in the trees");
    }else{
    g.drawImage(BackgroundImageTree.inorderTraversal(1),1,3,this);
    //g.drawImage(PlayerImageTree.inorderTraversal(1),55,150,this);
    import java.awt.*;
    import java.applet.Applet;
    class TreeNode {
    TreeNode left;
    Image data;
    TreeNode right;
    int value;
    public TreeNode(int weight,Image picture){
    left = right = null;
    value = weight;
    data = picture;
    public void insert(int v, Image newImage){
    if ( v< value){
    if (left ==null)
    left = new TreeNode(v,newImage);
    else
    left.insert(v,newImage);
    else if (v>value){
    if (right ==null)
    right = new TreeNode(v,newImage);
    else
    right.insert(v, newImage);
    public class Tree{
    private TreeNode root;
    public Tree() {
    root = null;
    public void insertImage(int value, Image newImage){
    if (root == null)
    root = new TreeNode(value,newImage);
    else
    root.insert(value,newImage);
    // in order search of tree.
    public Image inorderTraversal(int n)
    return(inorderHelper(root,n));
    private Image inorderHelper(TreeNode node, int n){
    Image temp = null;
    if (node == null)
    return null;
    if (node.value == n ){
    return(node.data);
    temp = inorderHelper(node.left,n);
    if (temp == null){
    temp = inorderHelper(node.right,n);
    return temp;
    }

    I can fix your problems
    1. You get an error here because you can only invoke the superclass's constructor in the subclass's constructor. It looks like that's what you're trying to do, but you're not doing it right. Constructors don't return any value (actually they do, but it's implied, so you don't need the void that you've got in your code)
    2. I'm not sure, but I think your call to show might be wrong. Move the setsize and setvisible calls to outside of the constructor

Maybe you are looking for