Applet repaint problem

Hi
I have problem with repainting. I add components to panel, then in action listener remove them and add a different component. After that the panel is empty, but when I resize the applet, the component appears.
Do you have any ideas what's wrong?
Here is the code:
public class test extends JApplet{
     private Container aplet;                                   
          private JPanel
               podspodnik = new JPanel(new BorderLayout());
          private JTextPane
               wyswietl = new JTextPane();          
          private JButton
               wywolaj = new JButton("Wywolaj"),
               but = new JButton("Juppi!");
          public void init()
               try
                    javax.swing.SwingUtilities.invokeAndWait(new Runnable()
                    public void run()
                         createAndShowGUI();
               catch (Exception noGUI)
                    System.err.println("Nie udalo sie utworzyc interfejsu!!");
                    JOptionPane.showMessageDialog(null,
                                   "Nie udalo sie utworzyc interfejsu!!!",
                                   "Blad krytyczny okna",
                                   JOptionPane.ERROR_MESSAGE);
          private void createAndShowGUI(){
               aplet = getContentPane();
               aplet.setPreferredSize(new Dimension(300, 300));
               wyswietl.setPreferredSize(new Dimension(200, 300));
               wyswietl.setPreferredSize(new Dimension(130,20));
               wywolaj.setPreferredSize(new Dimension(130, 20));
               podspodnik.add(wyswietl, BorderLayout.NORTH);
               podspodnik.add(wywolaj, BorderLayout.CENTER);
               aplet.add(podspodnik);
               addListeners();
               aplet.setVisible(true);
               aplet.repaint();
          private void addListeners(){
               wywolaj.addActionListener(new ActionListener()
                              public void actionPerformed(ActionEvent e)
                                   podspodnik.remove(wyswietl);
                                   podspodnik.remove(wywolaj);
                                   podspodnik.add(but, BorderLayout.CENTER);
                                   aplet.repaint();
}

Try to post this problem in the Java Applet Development forum instead.(
http://forum.java.sun.com/forum.jspa?forumID=421).
Applet != Servlet

Similar Messages

  • 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>

  • Initial repaint problem

    Hello all,
    Iam facing a repaint problem when i start my pgm. the display is distorted but when i minimize & maximize the window display is proper after that everything works fine. my pgm contains JApplet which in turn contains toobar, menubar scrollpane & a panel. the panel contaisn one more panel on which i'm drawing some data. when the pgm starts up the drawing is no in it's proper position i tried calling repaint, revalidate, paintAll .. all these commands in various places in various combination. i couldn't still solvemy problem. can anybody help me with this. the problem comes only when the window opens at first.
    Thanks in advance

    I also want to add one more thing if i run this as an application this problem doesn't comes. but i want to run this as an applet. is there anything special with the applet's paint method. please help me.

  • Some two threaded image prepare and painting applet coordination problem

    hi all,
    i'm sure this multithreaded gui is complex but anyway. a simple producer&consumer type applet. there is one seperate thread preparing an offscreen image, and the main guy draws it on applet. i can not coordinate them, what's wrong i don't know. simply, applet starts a thread, which paints something on an offscreen image, and then tells to applet repaint(). anyway, here is the code, this small png files are a lot, idea is making a view on them, just imagine a big big png file divided into matrices. afterall this is not the important part. what i see on the screen is, if you ask, nothing.
    thanx,
    ozz
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Point;
    import java.awt.Toolkit;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.lang.reflect.Array;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class MapViewer
         extends JFrame
         Image map[][];
         public MapViewer()
              int dimensions[] = { 58, 46 };
              map = (Image[][]) Array.newInstance(Image.class, dimensions);
              try
                   loadImages();
              catch(Exception e)
                   e.printStackTrace();
         public void loadImages()
              throws Exception
              for(int i=0; i<58; i++)
                   for(int j=0; j<46; j++)
                        StringBuffer sb = new StringBuffer();
                        sb.append("C:\\map\\");
                        sb.append(i+1);
                        sb.append("_");
                        sb.append(46-j);
                        sb.append(".png");
                        map[i][j] = Toolkit.getDefaultToolkit().getImage( sb.toString() );
         public void go()
              initComponents();
              show();
         private void initComponents()
              addWindowListener
                   new java.awt.event.WindowAdapter()
                        public void windowClosing(java.awt.event.WindowEvent evt)
                             exitForm(evt);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(new MapPanel(), BorderLayout.NORTH);
              pack();
         private void exitForm(java.awt.event.WindowEvent evt)
              System.exit(0);
         public static void main(String args[])
              new MapViewer().go();
         private class MapPanel
              extends JPanel
              implements MouseMotionListener, Runnable
              private int north = 1;
              private int east = 2;
              private int south = 4;
              private int west = 8;
              private int direction;
              private Image model;
              private Boolean refreshModel = Boolean.TRUE;
              private Boolean modelReady = Boolean.FALSE;
              private Point start = new Point(200, 200);
              public MapPanel()
                   addMouseMotionListener(this);
                   new Thread(this).start();
              public synchronized Image requestImage()
                   return createImage(1600, 1600);
              public Dimension getMinimumSize()
                   return new Dimension(400, 400);
              public Dimension getPreferredSize()
                   return new Dimension(400, 400);
              public void paint(Graphics g)
                   synchronized(modelReady)
                        if(modelReady.booleanValue() == true)
                             g.drawImage(model, 0, 0, null);
                   g.setColor(Color.white);
                   g.fillRect(0, 0, 30, 10);
                   g.setColor(Color.black);
                   g.drawString(String.valueOf(direction), 0, 10);
              public void mouseDragged(MouseEvent e)
              public void mouseMoved(MouseEvent e)
                   Point p = e.getPoint();
                   findDirection(p);
              private void findDirection(Point p)
                   direction = 0;
                   if(p.x < 100)
                        direction |= west;
                   else if(p.x > 300)
                        direction |= east;
                   if(p.y < 100)
                        direction |= north;
                   else if(p.y > 300)
                        direction |= south;
              public void moveIt()
                   int px = 20;
                   int py = 20;
                   synchronized(refreshModel)
                        if(refreshModel.booleanValue() == true)
                             model = requestImage();
                             if(model == null || model.getGraphics() == null)
                                  return;
                             Graphics g = model.getGraphics();
                             for(int x=0; x < 4; x++)
                                  for(int y=0; y<4; y++)
                                       g.drawImage(map[px+x][py+y], x*200, y*200, null);
                             refreshModel = Boolean.FALSE;
                             modelReady = Boolean.TRUE;
    //               start.x -= 3;
    //               start.y -= 3;
              public void run()
                   while(true)
                        try
                             moveIt();
                             repaint();
                             Thread.currentThread().sleep(20);
                        catch(InterruptedException ie)

    Hi.
    The Graphics.drawImage method is asynchronyous, that may be the reason of the problem. Set an ImageObserver parameter in drawImage method, when drawing on an offscreen image. Count finished images and when all are done
    draw the big image on the screen.
    Alternatively you can call Toolkit.prepareImage method in a loop, after loadimages and wait until all images are loaded(true returned).

  • Swing Applet Repainting during moving window

    Hi,
    I've run into a problem with my swing JApplet. One of the elements of my GUI is a JLabel that contains a single Image. After the GUI is created, a seperate thread changes the image and prompts the JPanel containing the JLabel to repaint().
    Now, this works perfectly with the AppletViewer using java 1.4.2.03. However, when I run the applet through Microsoft's Internet Explorer using Sun's VM 1.4.2.03 plugin, I notice a problem. If I take the window containing the applet and (assuming it is NOT maximized) move it around the screen, the JLabel's image will not always be drawn at the correct place. It will often overlap some of the other GUI elements.
    I read something that Threads and Applets don't mix which suggested using the SwingUtilities.invokeLater() function, but I need this Thread to sleep() and didn't know how to make it do so because I never see the Thread class through the invokeLater() method.
    It solves the problem if rather than have the JLabel repaint itself, I have the entire applet repaint itself, but this is not the ideal solution. Is there any way to determine when the window containing the applet is being moved and then force the applet to repaint itself entirely? Am I going about this wrong? Any help would be greatly appreciated!
    Thanks,
    B. Danny K.

    The content pane of a JApplet is a JPanel. So you need to use the getContentPane() method and cast the Compnent to a JPanel before you can use revalidate(). However, as you have discovered 99% of the time a validate() also works.
    Note, that is you are using a BorderLayout then you should be removing the old component before adding the new component.

  • Performance with repaint problem

    Hi,
    I have a performance and repaint problem.
    My problem is than I have a layer pane with about 500 JScrollPane, each JScrollPane has a JLabel, and each JLabel has an Icon. I can have to maintain this hierarchy.
    I have a thread that makes the icon change from a color state to a grey state; in fact it makes them all blink.
    My problem is that is takes 50% of the CPU when the blink thread is running. As well, they do not all blink at the same time. The thread changes the icon color and calls a repaint. They seem to repaint independently.
    What I would like is to collapse the paint calls into one without having to call repaint on the whole JFrame which does solve my problem but it is a hack.
    Swing should collapse all the repaints into one call to the parent but I think because of the JScrollPanes it is not. Can anyone shed any light into why it does not paint all in one call instead of 500 repaint calls.
    Thanks,
    Pat

    Well, I'd change the design first, but if you must play around with paint() then you can try using this setIgnoreRepaint(true) in the Component class.
    You could do the grouping yourself and then when you really want things repainted, flag all your components again with setIgnoreRepaint(false), and then call revlaidate() to the parent, and it should repaint everything at once. That is what's I'd try, anyway.

  • Repaint problem while clicking the popup menuitem

    Hi all,
    iam facing repainting problem in my application. User can initiate a single action from different options such as JButton, double-click of mouse and clicking the menu item form the JPopupMenu.
    All these will execute the same code. But when iam using the first two ways, the repainting is properly working and aim getting the required UI and opening the JInternalFrame.
    When the last case is being used(ie., clicking the menu item form the JPopupMenu), then the repaint is not working and the window being opened is coming in pieces and then finally i could see the window after some time, which is not the case with the first two cases.
    Please help me how to solve and get the window at once. Iam attaching the code.
    MainFrame.java
    package com.swing;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class MainFrame extends JFrame implements ActionListener{
         static final long serialVersionUID = 3345648L;
         public MainFrame() {
              setSize(1000,750);
              setLayout(null);
              setVisible(true);
              addMenuBar();
              invalidate();
         public void actionPerformed(ActionEvent actionEvent) {
              Object source = actionEvent.getSource();
              if( source == s_mnuItmFirstFrame ) {
                   FirstFrame s_frameFirst = new FirstFrame(this);
                   this.add(s_frameFirst);
          * @param args
         public static void main(String[] args) {
              MainFrame mFrame = new MainFrame();
         JMenuBar s_menuBar = null;
         JMenuItem s_mnuItmFirstFrame = new JMenuItem("Add Internal Frame");
         void addMenuBar(){
              Font fontNormal = new Font("Dialog", Font.PLAIN, 11);
              s_menuBar = new JMenuBar();
              s_menuBar.setDoubleBuffered(true);
              getRootPane().setJMenuBar(s_menuBar);
              s_mnuItmFirstFrame.setFont(fontNormal);
              s_mnuItmFirstFrame.addActionListener(this);
              JMenu s_menuFrames = new JMenu("Frames");
              s_menuFrames.setFont(fontNormal);
              s_menuFrames.add(s_mnuItmFirstFrame);
              s_menuBar.add(s_menuFrames);
    FirstFrame.java
    package com.swing;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.util.Vector;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.JTable;
    import javax.swing.event.InternalFrameAdapter;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.table.DefaultTableModel;
    public class FirstFrame extends JInternalFrame implements ActionListener
         static final long serialVersionUID = 2345657L;
         public FirstFrame(JFrame parentFrame) {
              super(" First Frame ", true, true, true, true);
              mainFrame = parentFrame;
              setSize(400, 400);
              setVisible(true);
              setLayout(new FlowLayout());
              try {
                   setMaximum(false);
              } catch (Exception e) {
                   e.printStackTrace();
              DefaultTableModel s_modelFirstTable = new DefaultTableModel();
              Vector tableData = new Vector();
              Vector namesVector = new Vector();
              namesVector.add("OneFirst");
              namesVector.add("OneMiddle");
              namesVector.add("OneLast");
              tableData.add(namesVector);
              namesVector = new Vector();
              namesVector.add("TwoFirst");
              namesVector.add("TwoMiddle");
              namesVector.add("TwoLast");
              tableData.add(namesVector);
              namesVector = new Vector();
              namesVector.add("ThreeFirst");
              namesVector.add("ThreeMiddle");
              namesVector.add("ThreeLast");
              tableData.add(namesVector);
              namesVector = new Vector();
              namesVector.add("FourFirst");
              namesVector.add("FourMiddle");
              namesVector.add("FourLast");
              tableData.add(namesVector);
              namesVector = new Vector();
              namesVector.add("FiveFirst");
              namesVector.add("FiveMiddle");
              namesVector.add("FiveLast");
              tableData.add(namesVector);
              Vector tableHeader = new Vector();
              tableHeader.add("First Name");
              tableHeader.add("Middle Name");
              tableHeader.add("Last Name");
              s_modelFirstTable.setDataVector(tableData, tableHeader);
              s_tblFirst.setModel(s_modelFirstTable);
              add(s_tblFirst);
              add(s_btnSecondButton);
              s_mnuPopupMenu.add(s_mnuItmSecondButton);
              s_mnuPopupMenu.add(s_mnuItmSecondButton1);
              s_mnuPopupMenu.add(s_mnuItmSecondButton2);
              s_mnuPopupMenu.add(s_mnuItmSecondButton3);
              s_mnuPopupMenu.add(s_mnuItmSecondButton4);
              s_tblFirst.addMouseListener(new MouseAdapter() {
                   public void mouseReleased(MouseEvent mouseEvent) {
                        s_mnuPopupMenu.setVisible(true);
                        // if (mouseEvent.isPopupTrigger()) {
                        s_mnuPopupMenu.show(mouseEvent.getComponent(), mouseEvent
                                  .getX(), mouseEvent.getY());
              s_btnSecondButton.addActionListener(this);
              s_mnuItmSecondButton.addActionListener(this);
              this.addInternalFrameListener(new InternalFrameAdapter() {
                   public void internalFrameClosing(InternalFrameEvent ifEvent) {
                        Object object = ifEvent.getSource();
                        if (object == FirstFrame.this) {
                             try {
                                  if (s_frameSecond != null)
                                       s_frameSecond.setClosed(true);
                             } catch (Exception e) {
                                  e.printStackTrace();
         public void actionPerformed(ActionEvent actionEvent) {
              if (s_frameSecond != null) {
                   try {
                        s_frameSecond.setClosed(true);
                   } catch (Exception e) {
                        e.printStackTrace();
              s_frameSecond = new SecondFrame();
              mainFrame.add(s_frameSecond);
              s_frameSecond.moveToFront();
              s_frameSecond.setVisible(true);
         JFrame mainFrame ;
         JTable s_tblFirst = new JTable();
         JButton s_btnSecondButton = new JButton("Second Frame");
         JMenuItem s_mnuItmSecondButton = new JMenuItem("Second Frame");
         JMenuItem s_mnuItmSecondButton1 = new JMenuItem("Second Frame1");
         JMenuItem s_mnuItmSecondButton2 = new JMenuItem("Second Frame2");
         JMenuItem s_mnuItmSecondButton3 = new JMenuItem("Second Frame3");
         JMenuItem s_mnuItmSecondButton4 = new JMenuItem("Second Frame4");
         JPopupMenu s_mnuPopupMenu = new JPopupMenu();
         SecondFrame s_frameSecond;
    SecondFrame.java
    package com.swing;
    import java.awt.GridLayout;
    import javax.swing.JButton;
    import javax.swing.JInternalFrame;
    public class SecondFrame extends JInternalFrame {
         static final long serialVersionUID = 1345648L;
         public SecondFrame() {
              super(" Second Frame ", true, true, true, true);
              try {
              setLayout(new GridLayout(4, 4));
              setSize(400,400);
              //setVisible(true);
              setMaximizable(true);
              for(int i=0; i<4; i++){
                   for(int j=0; j<4; j++){
                        add(new JButton(""+(i+1)+", "+(j+1)));
              catch(Exception e){
                   e.printStackTrace();
    }

    Don't post an IDE generated code as is. It's a torture for human eye. At least, you should rename
    all the identifiers to some meaningful names.
    You MUST use JDesktopPane when you use JInternalFrames.
    Here's a working code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.util.*;
    public class MainFrame extends JFrame implements ActionListener{
      static final long serialVersionUID = 3345648;
      JFrame frame;
      JDesktopPane jdp;
      public MainFrame() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(1000,750);
        // setLayout(null); //you MUST use a real LayoutManager
        addMenuBar();
        frame = this;
        jdp = new JDesktopPane();
        frame.add(jdp);
        setVisible(true);
      public void actionPerformed(ActionEvent actionEvent) {
        Object source = actionEvent.getSource();
        if( source == s_mnuItmFirstFrame ) {
          FirstFrame s_frameFirst = new FirstFrame(this);
          jdp.add(s_frameFirst);
          s_frameFirst.setVisible(true);
      public static void main(String[] args) {
        MainFrame mFrame = new MainFrame();
      JMenuBar s_menuBar = null;
      JMenuItem s_mnuItmFirstFrame = new JMenuItem("Add Internal Frame");
      void addMenuBar(){
        Font fontNormal = new Font("Dialog", Font.PLAIN, 11);
        s_menuBar = new JMenuBar();
        s_menuBar.setDoubleBuffered(true);
        getRootPane().setJMenuBar(s_menuBar);
        s_mnuItmFirstFrame.setFont(fontNormal);
        s_mnuItmFirstFrame.addActionListener(this);
        JMenu s_menuFrames = new JMenu("Frames");
        s_menuFrames.setFont(fontNormal);
        s_menuFrames.add(s_mnuItmFirstFrame);
        s_menuBar.add(s_menuFrames);
        setJMenuBar(s_menuBar);
    class FirstFrame extends JInternalFrame implements ActionListener{
      static final long serialVersionUID = 2345657;
      public FirstFrame(MainFrame parentFrame) {
        super(" First Frame ", true, true, true, true);
        mainFrame = parentFrame;
        setSize(400, 400);
        setVisible(true);
        setLayout(new FlowLayout());
        try {
          setMaximum(false);
        } catch (Exception e) {
          e.printStackTrace();
        DefaultTableModel s_modelFirstTable = new DefaultTableModel();
        Vector<Vector> tableData = new Vector<Vector>();
        Vector<String> namesVector = new Vector<String>();
        namesVector.add("OneFirst");
        namesVector.add("OneMiddle");
        namesVector.add("OneLast");
        tableData.add(namesVector);
        namesVector = new Vector<String>();
        namesVector.add("TwoFirst");
        namesVector.add("TwoMiddle");
        namesVector.add("TwoLast");
        tableData.add(namesVector);
        namesVector = new Vector<String>();
        namesVector.add("ThreeFirst");
        namesVector.add("ThreeMiddle");
        namesVector.add("ThreeLast");
        tableData.add(namesVector);
        namesVector = new Vector<String>();
        namesVector.add("FourFirst");
        namesVector.add("FourMiddle");
        namesVector.add("FourLast");
        tableData.add(namesVector);
        namesVector = new Vector<String>();
        namesVector.add("FiveFirst");
        namesVector.add("FiveMiddle");
        namesVector.add("FiveLast");
        tableData.add(namesVector);
        Vector<String> tableHeader = new Vector<String>();
        tableHeader.add("First Name");
        tableHeader.add("Middle Name");
        tableHeader.add("Last Name");
        s_modelFirstTable.setDataVector(tableData, tableHeader);
        s_tblFirst.setModel(s_modelFirstTable);
        add(s_tblFirst);
        add(s_btnSecondButton);
        s_mnuPopupMenu.add(s_mnuItmSecondButton);
        s_mnuPopupMenu.add(s_mnuItmSecondButton1);
        s_mnuPopupMenu.add(s_mnuItmSecondButton2);
        s_mnuPopupMenu.add(s_mnuItmSecondButton3);
        s_mnuPopupMenu.add(s_mnuItmSecondButton4);
        s_tblFirst.addMouseListener(new MouseAdapter() {
          public void mousePressed(MouseEvent mouseEvent){
            if (mouseEvent.isPopupTrigger()) {
              s_mnuPopupMenu.show(mouseEvent.getComponent(),
               mouseEvent.getX(), mouseEvent.getY());
          public void mouseReleased(MouseEvent mouseEvent) {
            if (mouseEvent.isPopupTrigger()) {
              s_mnuPopupMenu.show(mouseEvent.getComponent(),
               mouseEvent.getX(), mouseEvent.getY());
        s_btnSecondButton.addActionListener(this);
        s_mnuItmSecondButton.addActionListener(this);
        addInternalFrameListener(new InternalFrameAdapter() {
          public void internalFrameClosing(InternalFrameEvent ifEvent) {
            Object object = ifEvent.getSource();
            if (object == this) {
              try {
                if (s_frameSecond != null){
                  s_frameSecond.setClosed(true);
              } catch (Exception e) {
                e.printStackTrace();
      } // FirstFrame constructor
      public void actionPerformed(ActionEvent actionEvent) {
        if (s_frameSecond != null) {
          try {
            s_frameSecond.setClosed(true);
          } catch (Exception e) {
            e.printStackTrace();
        s_frameSecond = new SecondFrame();
        mainFrame.jdp.add(s_frameSecond);
        s_frameSecond.moveToFront();
        s_frameSecond.setVisible(true);
      MainFrame mainFrame ;
      JTable s_tblFirst = new JTable();
      JButton s_btnSecondButton = new JButton("Second Frame");
      JMenuItem s_mnuItmSecondButton = new JMenuItem("Second Frame");
      JMenuItem s_mnuItmSecondButton1 = new JMenuItem("Second Frame1");
      JMenuItem s_mnuItmSecondButton2 = new JMenuItem("Second Frame2");
      JMenuItem s_mnuItmSecondButton3 = new JMenuItem("Second Frame3");
      JMenuItem s_mnuItmSecondButton4 = new JMenuItem("Second Frame4");
      JPopupMenu s_mnuPopupMenu = new JPopupMenu();
      SecondFrame s_frameSecond;
    class SecondFrame extends JInternalFrame {
      static final long serialVersionUID = 1345648;
      public SecondFrame() {
        super(" Second Frame ", true, true, true, true);
        try {
          setLayout(new GridLayout(4, 4));
          setSize(400, 400);
          setMaximizable(true);
          for(int i=0; i<4; i++){
            for(int j = 0; j < 4; ++j){
              add(new JButton("" + (i + 1) + ", " + (j + 1)));
        catch(Exception e){
          e.printStackTrace();
    }

  • Applet socket problem in client-server, urgent!

    Dear All:
    I have implemented a client server teamwork environment. I have managered to get the server running fine. The server is responsible for passing messages between clients and accessing Oracle database using JDBC. The client is a Java Applet. The code is like the following. The problem is when I try to register the client, the socket connection get java.security.AccessControlException: access denied(java.net.SocketPermission mugca.its.monash.edu.
    au resolve)
    However, I have written a Java application with the same socket connection method to connect to the same server, it connects to the server without any problem. Is it because of the applet security problem? How should I solve it? Very appreciate for any ideas.
    public class User extends java.applet.Applet implements ActionListener, ItemListener
    public void init()
    Authentication auth = new Authentication((Frame)anchorpoint);
    if(auth.getConnectionStreams() != null) {
    ConnectionStreams server_conn = auth.getConnectionStreams();
    // Authenticates the user and establishes a connection to the server
    class Authentication extends Dialog implements ActionListener, KeyListener {
    // Object holding information relevant to the server connection
    ConnectionStreams server_conn;
    final static int port = 6012;
    // Authenticates the user and establishes connection to the server
    public Authentication(Frame parent) {
    // call the class Dialog's constructor
    super(parent, "User Authentication", true);
    setLocation(parent.getSize().width/3, parent.getSize().height/2);
    setupDialog();
    // sets up the components of the dialog box
    private void setupDialog() {
    // create and set the layout manager
    //Create a username text field here
    //Create a password text field here
    //Create a OK button here
    public void actionPerformed(ActionEvent e) {
    authenticateUser();
    dispose();
    // returns the ConnectionStreams object
    public ConnectionStreams getConnectionStreams() {
    return(server_conn);
    // authenticates the user
    private void authenticateUser() {
    Socket socket;
    InetAddress address;
    try {
    // open socket to server
    System.out.println("Ready to connect to server on: " + port);
    socket = new Socket("mugca.its.monash.edu.au", port);
    address = socket.getInetAddress();
    System.out.println("The hostname,address,hostaddress,localhost is:" + address.getHostName() + ";\n" +
    address.getAddress() + ";\n" +
    address.getHostAddress() + ";\n" +
    address.getLocalHost());
    catch(Exception e) {
    displayMessage("Error occured. See console");
    System.err.println(e);
                                  e.printStackTrace();
    }

    Hi, there:
    Thanks for the help. But I don't have to configure the security policy. Instead, inspired by a message in this forum, I simply upload the applet to the HTTP server (mugca.its.monash.edu.au) where my won server is running. Then the applet is download from the server and running fine in my local machine.
    Dengsheng

  • Applet running problem in ie 6.0 under Windows XP

    Applet running problem in ie 6.0 under Windows XP
    I have a PC running Iternet Explorer 6.0 running under Windows XP. I have developed an applet using JDK 1.3 which is running fine with applet viewer , but it is not running in ie. I have installed Netscape navigator and Opera 5. the applet is running fine in both of these browsers but somehow it is not running in IE.
    Later on I upgraded my JDK to 1.4. It also displays use Java2 (V1.4.1) for <applet> (requires restart) tck marked in Advance section under Tools-Options menu of IE.
    I have also tried and set various options in my Control Panel�s Java Plug-in but all in vain. I have searched the sites for this solution but no one answers specifically.
    I know it�s a small problem due to discarded JVM in IE under Windows XP but give me solution for that.
    Thanks in Advance
    [email protected]

    Dear I have the same problem .
    Applet running problem in 6.0 . Enen I have installed the latest Jre 1.5.
    What should I do. I am fedup with this problem.

  • OHJ4.1.16 Repainting Problems and 100%CPU on java 1.4

    Hi
    We are considering using OHJ4.1.16 as our application help, I have it working such that when the help is invoked either from the toolbar or the menu OHJ is displayed, but there are major repainting problems when the OHJ window is closed by clicking on the X button and then the help is invoked again from the toolbar or the menu item.
    Please note that the first time it displays and paints fine only when the OHJ frame is closed and invoked again the problem occurs
    The problems encountered are repainting(really whacky), 100% CPU utilization
    Please have a look at the code below and tell me if i am not doing it right, Also is there anyway i can trap events on the OHJ frame so that i can dispose it everytime the window is closed by the user??
    The following code is executed when the help is invoked
         public void startHelp()
         helpObject.showNavigatorWindow();     
         helpObject.setVisible(true);
         public static void launchApplication()
              String helpset1 = "/resources/help/Test.hs";
              Vector booksVector = new Vector();
              booksVector.add(helpset1);
                   if(m_instance == null)
                        m_instance = new ApplicationHelp(booksVector);
                   else
                        m_instance.startHelp();                    
    we are using java 1.4, the above problem makes OHJ unusable!!

    Hi, John. We're trying to reproduce your problem. If you run any of the OHJ 4.1.16 demos in the bin directory of the installation, do you run into the 100% CPU utilization problem? If so, how? The cshDemo.bat file creates a dummy application that has an OHJ deployment, so please test that one in particular.
    Thanks,
    Ryan

  • JTextpane positioning repaint problems

    Hello all,
    I have encountered a bug with JTextpane which I haven't found a solution for. I am new to Java and am revising previously written code, but I think this is a Java-related issue and not particular to my source code.
    I am writing html into a JTextPane-based class, yet on occasion, not keen to any particular scenarios, my text loses its position and drops one line. This is fixed by closing the window, hiding it or doing other things which I assume forces a repaint.
    This is very hard to debug. Is there a way to force all events to be called whenever I display the html textpane (like a VB6 DoEvents)? Has anyone encountered these repaint problems with JTextPane?
    Thanks in advance
    Eyal

    Thanks for the reply
    Could you please xplain what you mean by "subbing"?
    Anyhow I tried adding your suggestion but I am still encountering similar problems, and I can't debug because the symptoms don't appear in a consistent fashion.
    If anyone has any suggestions I'd love to know.
    Best regards
    Eyal

  • Applet Flash problem

    I have an applet and a flash in two frames in a HTML page. The applet and the falsh app communicate through the Javascript code with in the HTML pages. The flash app does not work as it is supposed to when the applet is present in the Parent HTML page. When I removed the applet, the flash app seems to work ok. But the applcation that I am working needs both of them together. Plz suggest me a solution if you know of any flash and applet related problems.
    Thanks in advance.
    kris

    http://forum.java.sun.com/thread.jsp?forum=31&thread=378703&start=0&range=15#1618263

  • Paint()/repaint() problem w/applet

    Hi all. Here's my dilemma: I'm trying to create an applet that asks for simple multiplication answers, and draws a string giving feedback after the question is answered ("Very good!" or "No, try again."). The problem is that the book says to draw everything from paint(), and gives the impression that repaint() should magically refresh everything on the applet, which it does not. How can I make the strings I drew in paint() go away and give way to new strings based on user answer (whether correct or not), instead of piling up on top of each other, because they don't refresh? Also, my JButton and JTextField aren't showing up until the mouse is scrolled over them. Thanks for your time!
    code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Week5Class extends JApplet implements ActionListener
        static int int1 = (int)(Math.random()*10);
        static int int2 = (int)(Math.random()*10);
        JTextField answer = new JTextField(3);
        JButton verifyAnswer = new JButton("Click to see if correct");
        public void init()
            Container myContainer = getContentPane();
            myContainer.add(answer);
            myContainer.add(verifyAnswer);
            verifyAnswer.addActionListener(this);
            myContainer.setLayout(new FlowLayout());
        static int j = 0;
        static int i;
        public void paint(Graphics gr)
              gr.drawString("How much is " + int1 + " * " + int2 + "?", 10, 70);
              if(i == 1)
                  gr.drawString("VeryGood!", 300, 200);
              else if(i == 0 && j != 0)
                  gr.drawString("No. Please try again.", 300, 200);
              j++;
        public void actionPerformed(ActionEvent e)
            int x = 300;
            int y = 200;
            if(Integer.parseInt(answer.getText()) == (int1*int2))
                int1 = (int)(Math.random()*10);
                int2 = (int)(Math.random()*10);
                i = 1;
                repaint();
            else
                i = 0;
                repaint();
    }

    The problem is that you're mixing doing your own drawing and using child objects. The paint method you've overriden would be the one that draws the text field and button.
    A far easier approach would be to use a JLabel to display your response message, and insert that as another component into the container, as you've inserted the button and input field.
    Then use setText() on the label to change the message.
    If you really want to have an area that you draw arbitary shapes on it's best to create your own child component, add it to the container, and override it's paintComponent method. Alternatively create a class which implments the Icon interface and put it in a JLabel.
    FlowLayout isn't very clever, by the way, try a BorderLayout or maybe a BoxLayout.

  • Repaint problems with an applet under Netscape 4.75

    Hello,
    I'm currently working on an applet created with VisualAge for Java, running under the standard Netscape 4.75 JVM, with Windows NT4.
    I am experiencing problems with AWT components which randomly disappear, especially Labels and sometimes Panels. When I drag a window over the missing label and then drag it back, the label appears.
    I have tried a lot of combinations with the repaint(), paint(), paintAll() and paintComponents() methods, but it has not been efficient for the moment. Introducing lots of repaint() calls on the concerned labels is even worse.
    Is there a known bug in the Netscape 4.75 JVM concerning this problem ? Do you have an idea of what can be done to solve this problem ? Changing the JVM is not an option that can be chosen. Netscape 4.75 has been defined as the only browser for the whole project.
    Thanks for your help !
    Kevin

    Well, I finally solved this problem.
    For your information, the JVM included in Netscape 4.75 running under NT4 does not like having AWT labels with either Background or Foreground not initialised. If any of these 2 properties is not defined, it could sometimes occur that the JVM can't display the label.

  • [APPLET][Heritage] Problem with classes

    Hi, I'm developping a simple JAVA Applet and I have a problem
    I have a class called LUIweb which is the main class. Here is a part of it.
    public class LUIweb extends JApplet implements Runnable {
    public void run() {
    DisplayMessage("JAVA rocks");
    public void DisplayMessage(String message){
    jtextArea.append(message);
    middlePanel.removeAll();
    middlePanel.add(textScrollPane, BorderLayout.CENTER);
    middlePanel.validate();
    middlePanel.repaint();
    It displays the message "JAVA rocks" in my JTextArea. But when another class from the same package calls DisplayMessage, nothing is displayed in my JTextArea
    public class Data_net extends LUIweb{
    public void Test(){
    DisplayMessage("NON");
    Have you got any idea to fix that?
    Thank you for you help

    OK,
    You are using a separate thread to update the gui. As swing is not multithread safe, this is not good. Anytime you want to change the gui, you must do it on the gui thread. This means without extra help, you should only change the gui from within a Listener, such as a MouseListener, KeyListener, etc, etc.
    In your case, you are updating the not from the gui thread (not from a Listener), and so you must ask the gui thread to do the work for you when it has time.
    This means you need to use SwingUtilities.invokeLater or SwingUtilities.invokeAndWait.
    Since the sequencing is important to you in your code, you should probably use invokeAndWait, such as
    public void run()
              SwingUtilities.invokeAndWait( new Runnable()
                     public void run() { DisplayMessage(Language.CONNECT_DB); }
              Data_net Donnee_net=new Data_net();          
              SwingUtilities.invokeAndWait( new Runnable()
                     public void run() { DisplayMessage("Connecting to "+Donnee_net.GetHost()+
                                                       " with user "+Donnee_net.GetUser()+"...\n");
              Donnee_net.Test();   

Maybe you are looking for

  • Excise Invoice capture

    Hello, We have one  company codes, L001 , normaly we are taking Excise , but not maintaining excise related entries (J1ID). Bcz our all materials are project based that goes to directly on site for site work. Our query is: we want to create PO and wa

  • Why can't I use my icloud feature?

    I cannot use my icloud feature?  It says I need to verify my email/password, but I've check my email and it tells me it's been verified.  Am I missing something?  I've been trying to use it for 3 days

  • Help needed finding logical Firebird replacement.

    A friend would like to buy my Firebird 803 but I am not sure what I can find that will replace it.   I need something quiet and unobtrusive for the TV room with easy hookups.  The Firebird right now is connected to the media system via 2 cables:  HDM

  • I have trouble with iCloud. I doest show my notes form my iPad?

    I have trouble with iCloud. I doest show my notes form my iPad?

  • Workflow Mailer Service not starting

    Hi Friends, My Environment OS : OEL4U5 Application Vers : R12.1.3 Db Version : 11.1.0.7 Hostname : erptest01 Here we configuring the Workflow Notification Mailer Service in our R12 instance. When we trying to start services in the workflow service co