Adding JApplet to JFrame

Hi
we can add an applet in JFrame(if it takes no parameters) e.g.
jFrameObject.getContentPane( ).add(anAppletObject);
but if an applet takes some parameters for initialization, then how i can pass parameters to that applet. means what is the code for passing parameters to an applet.
Thanks in Advance
Yahya Kamran

Well the key to your problem is an interface called "AppletStub".
What you need to do is define a own Class which implements AppletStub.
Therefore define methods to retrieve parameters or a constructor doing that and the one to get the parameters in your custom AppletStub.
The other methods must be implemented, too, but you can leave them blank, too. (eg. void foo() {} the empty braces are what makes the method implemented ;-) ).
Now do follwing:
// Creating the Applet you want to
SillyApplet anAppletObject  = new SillyApplet();
// Add it as you did
jFrameObject.getContentPane().add(anAppletObject);
// Now creating the parameters. This can be done how you like
// (maybe an ArrayList maybe something more sophisticated)
String[]  parameterList = new String[3];
parameterList[0] = "one parameter";
parameterList[1] = "another parameter" ;
parameterList[2]  = "something special";
parameterList[3] = "the last thing ever";
// Assume your custom stub accepts a String[] of parameters int it's constructor
// This is how to create such a mean Stub thing
WeirdStub stub  = new WeirdStub(parameterList);
// Handing the stub over to the applet
anAppletObject.setStub(stub);
// Now let the Applet get loose!
anAppletObject.init();
anAppletObject.start();Please note thus the Applet is added to the JFrame, you are still taklking to the same mean object!
This is called reference semantics, since the variable actualy represents a pointer to the Object you are talking about.
Another note this has to work a kind like that since the applet viewer is a java programm it self and various ide offer such a thing, too and are of course written in java, too.
When stuck report in again.
Greetings to your feetings,
.o0|LIQID|0o.
Found it in the java api source code.

Similar Messages

  • Please let me know what steps need to take to convert JApplet to JFrame

    I have an application which needs to convert from JApplet to JFrame....Please let me know what are the steps need to take for this

    I have an application which needs to convert from
    JApplet to JFrame....The topic of this forum is web-start, and it
    can be used to launch both applets and
    applications. An applet deployed using
    web-start avoids a lot of the browser related
    problems that affect 'embedded' applets.
    This leads me to..
    Please let me know what are the steps need to take for this You do not need to convert it, to launch it
    using web-start, but if you are determined to
    make it into a frame, it would be best to ask
    how to do that on a forum where the subject
    being talked about, is closer to what you are
    doing.
    For more closely related forums, try here
    http://forum.java.sun.com/category.jspa?categoryID=5
    (More the first two of the Available Forums:)

  • Need to convert JApplet to JFrame

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

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

  • JApplet with JFrame fails to load in browser

    I have been making a Java program that runs a JApplet the program operates perfectly in NetBeans (the Java development kit), but when I run it in the browser, it fails to load.
    The code is...
    import java.awt.*;
    import javax.swing.*;
    public class CalculatorMain extends javax.swing.JApplet {
    private Difficulty difficulty = new Difficulty();
    private Troop[] troop = new Troop[7];
    private Army army = new Army(troop);
    private Calculator calculator = new Calculator(difficulty, army);
    private CalculatorListener listener;
    public void init(){
    JPanel supreme = new JPanel();
    supreme.setLayout(new BorderLayout());
    for (byte i = 0; i < 7; i++) {troop[i] = new Troop();}
    DifficultyPanel diffpanel = new DifficultyPanel(difficulty);
    ArmyPanel armypanel = new ArmyPanel(troop);
    JButton calbut = new JButton("Calculate Experience");
    JLabel xpDisplay = new JLabel(" ");
    CalculatorPanel calpanel = new CalculatorPanel(calculator, calbut, xpDisplay);
    JFrame frame = new JFrame();
    listener = new CalculatorListener(xpDisplay, calculator, diffpanel, armypanel, calpanel);
    calbut.addActionListener(listener);
    supreme.add(diffpanel, BorderLayout.WEST);
    supreme.add(armypanel, BorderLayout.CENTER);
    supreme.add(calpanel, BorderLayout.SOUTH);
    frame.add(supreme);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
    As I said, it does not work in the web browser (which is Internet Explorer 6.0). In the information window I open, the message is...
    Java Plug-in 1.5.0_06
    Anv�nder JRE-version 1.5.0_06 Java HotSpot(TM) Client VM
    java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkExit(Unknown Source)
         at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
         at CalculatorMain.init(CalculatorMain.java:31)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-CalculatorMain.class" java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletException(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Any idea what might be wrong?

    If you look at your error message you'll see...
    java.security.AccessControlException: access deniedAh. Problem # 1 caused at
         at CalculatorMain.init(CalculatorMain.java:31)Problem #2
    java.lang.NullPointerExceptionat
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)So it says it can't display the init error message. That's ok this should go away when you fix bug #1

  • Putting JApplet into JFrame

    Hi, does anyone know how to combine a JApplet into a JFrame conponent? I've tried:
    public static void main(String args[]) {
    final JFrame frame=new JFrame();
    JApplet applet=new JApplet(); // JApplet is the class name
    applet.init();
    frame.setContentPane(applet.getContentPane());
    frame.setBounds(20, 20, background.getWidth(null)+2, 702);
    frame.setVisible(true);
    frame.addWindowListener(new WindowAdapter() {
    public void winodwClosing(WindowEvent e) {
    System.exit(0);
    but it's not working. I'm using Appletviewer. Pllease help if u know the answer. Thx!

    instead of:
    frame.setContentPane(applet.getContentPane());you need to do:
    frame.getContentPane().add(applet);

  • Adding JTree to JFrame using SpringLayout

    I have created a JTree with various nodes and leafs. I want to place the JTree in a GUI that uses SpringLayout as the layout manager. What should I use to place the JTree in the JFrame? I assume I put it in a JScrollPane which serves as a container. Then how do I assign a layout manager to JScrollPane and register it with the JFrame? Does this make sense?

    Twupack, my apologies. I was not receiving any responses in the other forum so I decided to take my questions to the beginner form which is probably more suitable given the complexity of my question. I also asked a different question - regarding the same topic. And my login, although different, was not intentional. This forum asked me to enter a different login name so I did. If I really wanted to hide my identity, I think I could have figured out something a little more creative.
    Now, mods, if you could, remove this thread as I am not receiving any useful responses here.

  • Adding wallpaper to jframe

    hi,
    does anyone know how to set the background of a jframe to a wallpaper?
    thanks.

    Check out this thread:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=316074

  • Adding shortcuts to JFrame

    I have menus in a JFrame. Each JMenuItem lunches differents JInternalFrame. I want the JFrame to lunch MenuItem Action while using Function Keys like F1 etc.
    I used setMnemonic()... but doesn't work. I used JFrame implements KeyListener but, Dunno why, work sometimes. What I have to do?
    Thanks a lot

    How to Use Menus:
    http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html
    I used setMnemonic()... You should be using an accelerator.

  • Adding video in jframe?

    help please.. how can i add a video in a jframe? is it possible?

    how? i cant understand it. plesae teach me........T_TYou can do this. You just need JMF. Check out this code
    import javax.swing.*;
    import javax.media.*;
    import java.net.*;
    import java.io.*;
    public class JMFVideo1
         public static void main(String args[]) throws Exception
              Player player;
              JFrame jframe=new JFrame();
              jframe.setSize(300,300);
              JPanel jpanel=new JPanel();
              jpanel.setLayout(new BoxLayout(jpanel,BoxLayout.Y_AXIS));
              player=Manager.createRealizedPlayer(new MediaLocator(new File("G:/java files1/jmf/love.mpg").toURL()));
              player.setMediaTime(new Time(30.0));
              jpanel.add(player.getVisualComponent());
              Control controls[]=player.getControls();
              CachingControl cc=null;
              for(int i=0;i<controls.length;i++)
                   if(controls[i] instanceof CachingControl)
                        cc=(CachingControl) controls;
                        jpanel.add(cc.getProgressBarComponent());     
                        System.out.println("Found CachingControl");
              if(player.getControlPanelComponent()==null)
                   System.out.println("Null");
              else
                   jpanel.add(player.getControlPanelComponent());
              jframe.setContentPane(jpanel);
              jframe.setVisible(true);
              player.start();

  • Adding and showing jframe

    hi friends
    i add my project 10 jframe and one of them is my parents frame
    when user click to button1 jframe1 open after click to button2 then jframe1 close and jframe2 open.
    these buttons are in parent form. please help me for this situation.
    thanks everyone.

    [http://catb.org/~esr/faqs/smart-questions.html]
    To get better help sooner, post a SSCCE that clearly demonstrates the problem.
    To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    db

  • How to call html which holds JApplet from Jframe class

    Any one got idea please go ahead...its very urgent for the project..Thanks in advance

    Tulasi 1243 wrote:
    Thanks It's working.
    But, at the time of changing the first record only it working. how can we give for different records ?What do you mean by different records? is it different rows?
    Then how are you going to handle the multiple rows data into one apex page item??
    It seems like you have something like a manual tabular form?? why don't you use apex API's for that
    The best way is to create a manual tabular form using apex api's and then process the data.
    because in pl/sql am using cursor to display multiple data.What makes the column unique for each row in your case? for example APEX assigns a unique ID attribute for each input element

  • Adding a JPanel from one class to another Class (which extends JFrame)

    Hi everyone,
    So hopefully I go about this right, and I can figure out what I'm doing wrong here. As an exercise, I'm trying to write a Tic-Tac-Toe (TTT) game. However, in the end it will be adaptable for different variations of TTT, so it's broken up some. I have a TTTGame.java, and TTTSquareFrame.java, and some others that aren't relavent.
    So, TTTGame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              addPanel = startSimple();
              if(!addPanel.isValid())
                   System.out.println("Something's wrong");
              contents.add(addPanel);
              setSize(300, 300);
              setVisible(true);
         public JPanel startSimple()
              mainSquare = new TTTSquareFrame(sides);
              mainSquarePanel = mainSquare.createPanel(sides);
              return mainSquarePanel;
    }and TTTSquareFrame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.Misc;
    public class TTTSquareFrame
         private JPanel squarePanel;
         private JButton [] squares;
         private int square, index;
         public TTTSquareFrame()
              System.out.println("Use a constructor that passes an integer specifying the size of the square please.");
              System.exit(0);
         public TTTSquareFrame(int size)
         public JPanel createPanel(int size)
              square = (int)Math.pow(size, 2);
              squarePanel = new JPanel();
              squarePanel.setLayout(new GridLayout(3,3));
              squares = new JButton[square];
              System.out.println(MIN_SIZE.toString());
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setRolloverEnabled(false);
                   squares[i].addActionListener(bh);
                   //squares[i].setMinimumSize(MIN_SIZE);
                   squares[i].setVisible(true);
                   squarePanel.add(squares[i]);
              squarePanel.setSize(100, 100);
              squarePanel.setVisible(true);
              return squarePanel;
    }I've successfully added panels to JFrame within the same class, and this is the first time I'm modularizing the code this way. The issue is that the frame comes up blank, and I get the message "Something's wrong" and it says the addPanel is invalid. Originally, the panel creation was in the constructor for TTTSquareFrame, and I just added the mainSquare (from TTTGame class) to the content pane, when that didn't work, I tried going about it this way. Not exactly sure why I wouldn't be able to add the panel from another class, any help is greatly appreciated.
    I did try and cut out code that wasn't needed, if it's still too much let me know and I can try and whittle it down more. Thanks.

    Yea, sorry 'bout that, I just cut out the parts of the files that weren't relevant but forgot to compile it just to make sure I hadn't left any remnants of what I had removed. For whatever it's worth, I have no idea what changed, but something did and it is working now. Thanks for your help, maybe next time I'll post an actual question that doesn't somehow magically solve itself.
    EDIT: Actually, sorry, I've got the panel working now, but it's tiny. I've set the minimum size, and I've set the size of the panel, so...why won't it respond to that? It almost looks like it's being compressed into the top of the panel, but I'm not sure why.
    I've compressed the code into:
    TTTGame.java:
    import java.awt.*;
    import javax.swing.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              mainSquare = new TTTSquareFrame(sides.intValue());
              contents.add(mainSquare);
              setSize(400, 400);
              setVisible(true);
    }TTTSquareFrame.java
    import java.awt.*;
    import javax.swing.*;
    public class TTTSquareFrame extends JPanel
         private JButton [] squares;
         private int square, index;
         private final Dimension testSize = new Dimension(50, 50);
         public TTTSquareFrame(int size)
              super();
              square = (int)Math.pow(size, 2);
              super.setLayout(new GridLayout(size, size));
              squares = new JButton[square];
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setMinimumSize(testSize);
                   squares[i].setVisible(true);
                   super.add(squares[i]);
              setSize(200, 200);
              setVisible(true);
    I've made sure the buttons are smaller than the size of the panel, and the panel is smaller than the frame, so...
    Message was edited by:
    macman104

  • Multithreaded Pacman: only last animated panel added to JFrame is displaye

    Hello,
    I am making a multithreaded pacman game. Pacman and each of the ghosts run in a separate thread.
    However, only the last item (ie. pacman or one of the ghosts) added to the JFrame is displaying in the maze. (pacman and each of the ghosts are subclasses of JPanel). For example, if I do:
    add(pacman);
    add(orangeGhost);
    add(redGhost);
    only the red ghost animation will appear on the maze(which is also a subclass of JPanel).
    I have tried adding the ghosts to pacman and then adding pacman i.e. pacman.add(redGhost); add(pacman); but this still doesn't work - only pacman is showing in the maze.
    Each thread runs fine on its own, but only the last one added is displaying.
    Any help is much appreciated.

    Hi,
    JFrame uses the BoderLayout layout manager, and when you add a JPanel after the other inside your JFrame they will get put one on top of other. None of the layout manager let you overlap components with transparency as far as I know. Also your JPanels are not transparent but opaque.
    I think what you need is to "paint" your game on a JPanel o canvas, take a look at this tutorial:
    http://javaboutique.internet.com/tutorials/Java_Game_Programming/
    Keep asking around, people with more experience can help you on this forum.
    Regards,

  • JApplet has null JLayerdPane

    I have a JApplet that adds a JInternalFrame to its default JLayeredPane in its constructor. The JInternalFrame was visible and worked fine when the Applet was run alone in a browser or when it was added to a JFrame as part of an application. However, I've recently tried to use as part of another Applet where it is added as a component in a CardLayout. Now the InternalFrame does not appear. When I check the result of getLayeredPane() in the JApplet's constructor, null is returned. Any ideas?

    I have a JApplet that adds a JInternalFrame to its default JLayeredPane in its constructor. The JInternalFrame was visible and worked fine when the Applet was run alone in a browser or when it was added to a JFrame as part of an application. However, I've recently tried to use as part of another Applet where it is added as a component in a CardLayout. Now the InternalFrame does not appear. When I check the result of getLayeredPane() in the JApplet's constructor, null is returned. Any ideas?

  • Java Graphics -- Drawing Strings on JFrame

    Hello and thank you. I'm relatively young and I apologize for asking noob questions. The problem I am having is that I realized after 3 hours of research and then writing this code that when multiple JPanels are added to a JFrame, they overlap (I think) over each other. As a result, the output of this program below is at the bottom right of the frame, the number 841 appears (the last number in my array) and everything else is blank.
    And I could not at all understand how to create graphics objects. It kept giving me an error of not being able to be instantiated. And to be honest, I don't even really understand whats going on when I add the text to my JPanel. I never call paintComponents. And definately I could never even make a graphics object to provide it the parameter required. Anyway, I resolved to use Jpanels because they can be removed using the remove function of the JFrame. And It is vitally important that I can delete the strings off my frame. Here is my code:
    package main;
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    public class VisualFrame extends JFrame{
        ArrayList<JPanel> numbers = new ArrayList<JPanel>();
        public VisualFrame(){
            setSize(1000, 500);
            setTitle("Binary Search");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        public void createPanels(int[] array){
            int x = 10;
            int y = 20;
            int xOffset = 50;
            int yOffset = 50;
            for(int i=0; i<array.length; i++){
                String num = Integer.toString(array);
    numPanel panel = new numPanel(num, x, y);
    numbers.add(panel);
    add(panel);
    x = x+xOffset;
    if(x>this.getWidth()){
    x = 10;
    y = y+yOffset;
    class numPanel extends JPanel{
    String num;
    int x;
    int y;
    public numPanel(String str, int x, int y){
    num = str;
    this.x = x;
    this.y = y;
    public void paintComponent(Graphics g){
    g.setColor(Color.black);
    g.setFont(new Font("Times", Font.BOLD, 12));
    g.drawString(num, x, y);
    My main method is inside of a different class:
        public static void main(String[] args){
            VisualFrame frame = new VisualFrame();
            frame.createPanels(array);
        }Firstly, do I even have the problem I'm having right? If so,
    Is there a way to restrict the size of the panels to the length and width of what it contains?
    Or can someone give me a good, very detailed link to how to use Graphics? Or perhaps someone could prove to me a good method.
    Edited by: 989946 on Mar 8, 2013 6:45 PM

    Why don't you start by learning from the experts?
    The Java Tutorial has sections that show how to use Java functionality.
    http://docs.oracle.com/javase/tutorial/
    The Graphiics section covers GUI and Swing
    http://docs.oracle.com/javase/tutorial/uiswing/index.html
    >
    Creating Graphical User Interfaces
    Creating a GUI with Swing — A comprehensive introduction to GUI creation on the Java platform.
    >
    And that section has links for trails such as how to use ALL of the different swing components including frames and panels
    http://docs.oracle.com/javase/tutorial/uiswing/components/index.html
    >
    Using Swing Components tells you how to use each of the Swing components — buttons, tables, text components, and all the rest. It also tells you how to use borders and icons.

Maybe you are looking for

  • Acrobat 9 pro Extended - IE Select Button

    Using windows xp sp3 and Internet Explorer 7 with all latest updates... When Verion 9 is installed, it adds a toolbar to IE. The toolbar has a button called select. I am not sure what you do after you select something on a web page. Can you copy it?

  • ITunes freezes when syncing with iPhone, but works fine with iPod?

    It's a bit of a long story with my iPhone/iTunes problem. In late July, my iPhone stopped syncing properly. It's an iPhone 4. Basically, I tried to add more photo albums to sync onto my phone, something I have done before. It began syncing, then noti

  • Need a form building app

    I need an app that can present a form that we design and then save the data LOCALLY to the tablet.  I do NOT want an app that needs to save it to a vendor server and has a per month per user cost.  This is a one page form that our inspectors currentl

  • How to use the first row function value for the rest of records

    Hi all, I am having a select statement like this. We are calling function enabled for each row. So it is taking time. As per our bussiness logic, we can use what the function 'enabled' will give for the first row to other rows also. so that we can av

  • Can't open sticky notes

    I transferd an old Windows XP hard drive into a new Windows 8 pc. I can open the older pdf files in Reader XI, I can see the Icons of the sticky notes made last year, but to scroll or click on them does nothing. I can make new sticky notes and the ne