MenuBar in JAPPlet

Can Someone please help me, i've created a menubar with menuitems in a JFrame but i dont no how to do it in a JApplet. I would appreciate anybodies help.

This is the code I've used but It wont work      
public void setJMenuBar(JMenuBar menubar)
          //puts a menubar in application
          JMenuBar bar = new JMenuBar();
          setJMenuBar(bar);
          JMenu fileMenu = new JMenu("File");
          fileMenu.setMnemonic('F');
          JMenuItem exit = new JMenuItem("Exit");
          exit.setMnemonic('x');
          exit.addActionListener
          new ActionListener()
     public void actionPerformed( ActionEvent e)
     System.exit(0);
          }//actionperformed()
     }//ActionLIstener()
     fileMenu.add(exit);
     bar.add(fileMenu);
     public JMenuBar getJMenuBar(JMenuBar menubar)
          return menubar;
     }

Similar Messages

  • JMenu Mnemonic in  JApplet not working

    Hi,
    Here is a code in my JApplet, but some how the Mnemonic is not working,
    why??
    I m using jdk1.4.1
    Ashish
    import javax.swing.text.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.*;
    import java.awt.*;
    import java.math.*;
    import javax.accessibility.*;
    public class TestMenuApplet extends JApplet
         public void init()
    buildMenu();
         private void buildMenu()
         JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("File", true);
    JMenu format = new JMenu("Format", true);     
    file.setMnemonic(KeyEvent.VK_F);
    format.setMnemonic(KeyEvent.VK_O);
    JMenuItem back = new JMenuItem("Back");
    JMenuItem close = new JMenuItem("Close");
    JRadioButtonMenuItem single =
    new JRadioButtonMenuItem("Single");
    JRadioButtonMenuItem multi =
    new JRadioButtonMenuItem("Multiple", true);
         ButtonGroup row = new ButtonGroup();
         row.add(single);
         row.add(multi);
    JMenu monthly = new JMenu("Monthly");
    JMenuItem one = new JMenuItem("One", KeyEvent.VK_O);
    JMenuItem two = new JMenuItem("Two");
    JMenuItem test = new JMenuItem("Test");
    menuBar.add(file);
    menuBar.add(format);
    file.add(back);
    file.add(close);
    format.add(single);
    format.add(multi);
    format.addSeparator();
    format.add(monthly);
    format.add(test);
    monthly.add(one);
    monthly.add(two);
    this.setJMenuBar(menuBar);
    My HTML
    <html>
    <HEAD>
    <TITLE>test</title>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="-1">
    </HEAD>
    <BODY >
    This is testing of applet
    <br>
    <!--"CONVERTED_APPLET"-->
    <!-- HTML CONVERTER -->
    <OBJECT
    classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    WIDTH = "300" HEIGHT = "300"
    codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4-win.cab#Version=1,4,0,0">
    <PARAM NAME = CODE VALUE = "TestMenuApplet.class" >
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.4">
    <PARAM NAME="scriptable" VALUE="false">
    <COMMENT>
         <EMBED
    type="application/x-java-applet;version=1.4"
    CODE = "TestMenuApplet.class"
    WIDTH = "300"
    HEIGHT = "300"
    scriptable=false
         pluginspage="http://java.sun.com/products/plugin/index.html#download">
         <NOEMBED>
              </NOEMBED>
         </EMBED>
    </COMMENT>
    </OBJECT>
    <!--
    <APPLET CODE = "TestMenuApplet.class"
    WIDTH = "300"
    HEIGHT = "300"
    </APPLET>
    -->
    <!--"END_CONVERTED_APPLET"-->
    </BODY>
    </html>

    Did you convert your html code to call the sun VM instead of the default browser VM ?
    Use the HtmlConverter.exe to do this passing the html file in argument.
    Denis

  • How to make a Multiple-rows Swing menubar?

    Hello!
    I'd like to le JMenubar to show multi-rows automatically in JFrame or JApplet if one row can not show all menus.
    Does anyone know how to do it? (I've asked several times these days but seems no one knows answer)
    Thank you very much.

    If your design requires that many menubar items that it can't be displayed on a normal window, then perhaps you should reconsider your design. If you really think it is your only option than you can try changing the layout of the menubar.JMenuBar mb = new JMenuBar();
    mb.setLayout(new GridLayout(5, 2));

  • JMenus  with (JApplet inside JInternalFrame)

    Hi all,
    I am trying to display a JApple in JInternalFrame, all this components are in a JFrame with some JMenus
    The problem: when I click a JMenu to display its JMenuItems, these JMenuItems appears to be displayed behind the JApplet.
    Can any expert help me with this??
    My code is something like that:
    import java.awt.*;
    import javax.swing.*;
    public class MyFrame extends JFrame
         public MyFrame()
              super("My Frame");
              //Create the menu bar.
         JMenuBar menuBar = new JMenuBar();
              this.setJMenuBar(menuBar);
         //create Menus and add them to the MenuBar
              JMenu fileMenu = new JMenu("File");
              JMenu playMenu = new JMenu("Play");
         menuBar.add(fileMenu);
              menuBar.add(playMenu);
              //Create MenuItems
         JMenuItem new1 = new JMenuItem("New...");
              JMenuItem open = new JMenuItem("Open...");
              JMenuItem exit = new JMenuItem("Exit");
              JMenuItem start = new JMenuItem("Start");
              JMenuItem stop = new JMenuItem("Stop");
              JMenuItem next = new JMenuItem("Next");
              JMenuItem previous = new JMenuItem("Previous");
              //add menuItems in the menus
         fileMenu.add(new1);
              fileMenu.add(open);
              fileMenu.addSeparator();
              fileMenu.add(exit);
         playMenu.add(start);
         playMenu.add(stop);
         playMenu.add(next);
         playMenu.add(previous);
              //Internal Frame in the CENTER
              JInternalFrame internalFrame = new JInternalFrame("Internal Frame", false, false, false);
         this.add(internalFrame, BorderLayout.CENTER);
    internalFrame.add(new JApplet());
              internalFrame.pack();
              internalFrame.setVisible(true);
         public static void main(String[] args)
              JFrame frame = new MyFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setVisible(true);
              frame.setExtendedState(MAXIMIZED_BOTH);
    }

    You need to set the menus to be heavyweight:
    fileMenu.getPopupMenu().setLightWeightPopupEnabled(false);
    playMenu.getPopupMenu().setLightWeightPopupEnabled(false);Read here about it:
    http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html#popup
    Also usually, you add internal frames to a desktop pane.
    Read the tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html

  • How to add JMenuBar to a JApplet?

    I have created a MenuApplet.java class which extends JApplet. I am tring to drag and drop JMenuBar on to the form but the menu bar is not visible. The menu bar is only visible when I try to check the preview. But the auto generated code shows that JMenuBar is added.
    I have created a MenuBar.java class which extends JFrame. I am tring to drag and drop JMenuBar on to the form and the menu bar is visible.
    What should I do to over that JApplet so that I can use it like a JFrame by adding menubar, labela, buttons, text panes and drop downs.

    For this problem I have found one solution where I will be creating one more java class which extends JFrame and I will be calling this class when the applet gets started. But at the same time the default applet viewer and the JFrame are visible. Can you help me out in hiding the default applet viewer so that only the JFrame is visible.
    How I have done is like as follows:
    public class MenuApplet extends JApplet {
        /** Initializes the applet MenuApplet */
        @Override
        public void init() {
            MenuFrame mFrame = new MenuFrame();
            mFrame.setVisible(true);
            //this.stop();
            //this.destroy();
    }Here, MenuFrame is the java class which extends JFrame. Even stop() and destroy() methods are not helpful for me.

  • Open JApplet with new java plugin ??

    Hi,
    I want to open an applet with new java run time envorinment, i.e. i must see 2 java consoles in the windows tray
    here is my code in html, but the problem is they work in same jvm..
    how do i make them work in different jvm
    Hope i am clear, if not i will explain more in detail
    <script language="JavaScript1.2">
    function openPlanApplet()
    TheNewWin = window.open('AppletTest.htm', '');
    // where AppletTest.htm is the html which has applet defined in it
    TheNewWin.moveTo(-10, -0);
    Ashish

    HI,
    I think i will get 2 consoles, but the problem is the end user will be forced have 2 jvm installed on his machine, also what if i want 3 applets in 3 different envoriment , then
    Let me send u some example of what i am trying to do
    This is my java Applet, and there are 2 HTML files,
    first open test.html and then click button to open the applet window, then click on the button "GO" in applet to change the text of label
    , then go back to test.html and again click on the button to open applet u will see that the button text is "change it" instead of "Applet1"
    and that is why i want to start a new jvm window to avoid this
    Hope this makes sense,
    or send me an email at [email protected] and i will send u a zip file of all html and class file for u to test
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    public class AppletTest extends JApplet
    implements ActionListener
    public static String name = "Applet1";
    JLabel label;
    public void init()
    JButton b = new JButton("go");
    b.addActionListener(this);
    label = new JLabel(name);
    this.getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT, 20,50));
    this.getContentPane().add(b);
    this.getContentPane().add(label);
    this.setSize(100,100);
    public void actionPerformed(ActionEvent ae)
    name="Change it";
    label.setText(name);
    // end of code
    /** test.html
    <html><head>
    <title>Test Screen size</title>
    <script language="JavaScript1.2">
    var TheNewWin;
    function openPlanApplet()
    TheNewWin = window.open('AppletTest.html', '', config='height=300, width=300, toolbar=no, menubar=no,scrollbars=no,resizable=no, location=no,directories=no, status=no ,offscreenBuffering=false');
    TheNewWin.moveTo(-10, -0);
    </SCRIPT>
    </head>
    <body bgcolor="#ffffff">
    Open new window
    <br>
    <input type="button" value="Open Window" onclick="openPlanApplet()">
    </body>
    /** AppletTest.html
    <html>
    <head>
    <title> test applet </title>
    </head>
    <body>
    This is testing of applet
    <br>
    <applet code="AppletTest.class" WIDTH = "800" HEIGHT = "600">
    </applet>
    </body>
    </html>
    **/

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

  • Can you show applications open directly in menubar instead of dock?

    Hi there
    I want to disable dock totally
    But I want to get the functionality in my menu bar
    So i want to show icons of the apps which are open (or at least favourite apps), directly on the menubar
    I don't want them in a folder, I already have an app which does that called xMenu
    I want the actual icons of the Favourite/IfPossible:OPEN apps to directly appear in menubar
    Is there anything that can get some/all of this functionality?

    Well, there probably is; however, a word of caution: the Menu bar is controlled by the System and it may have undesirable results changing system behavior.
    What is it about the dock that bothers you?
    I have all the apps I use on a regular basis in the dock - not a folder, mind you - alias icons to the apps themselves which all open with one click. I rarely use the system supplied Applications folder in the dock. At last count, I had almost 60 app icons in the dock, which is minimized with significant magnification - I have them organized so I can usually hit the right one without having to search. You can also check "automatically show and hide the Dock" so it'll only show itself when moving the cursor over the area.

  • The menubar will not display in full screen

    Hi.
    I have a strange problem in fullscreen mode, on my Macbook pro 15"
    I LOVE fullscreen, and infact the next macbook I will get is the 11" air because of its size and because full screen is so nice to work with.
    But I have a strange problem which I can't find a solution for.
    Suddenly the menubar will not display it self when I move the mouse to the top of the screen. The only way I can access the menu bar is by exiting full screen (ctrl + Cmd + F) and the toggel it back on after I have used the menubar
    This actually makes fullscreen mode useless and its driving me nuts, because this should not happen on Apple software. I would expect these sorts of behaviour on windows but not in osx.
    Anybody have a hint about what to do?

    https://discussions.apple.com/thread/3881124?start=0&tstart=0     <<<<< GO THERE
    Try this:  make a temporary, backup copy (if you don't already have a backup copy) of the library and try the following:
    1 - delete the iPhoto preference file, com.apple.iPhoto.plist, that resides in your
         User/Home()/Library/ Preferences folder.
    2 - delete iPhoto's cache file, Cache.db, that is located in your
         User/Home()/Library/Caches/com.apple.iPhoto folder. 
    Click to view full size
    3 - launch iPhoto and try again.
    NOTE: If you're moved your library from its default location in your Home/Pictures folder you will have to point iPhoto to its new location when you next open iPhoto by holding down the Option key when launching iPhoto.  You'll also have to reset the iPhoto's various preferences.

  • How to update a JPanel in a JApplet

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

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

  • Is correct? Application (JFrame) to Applet (JApplet)

    I need to convert a java application (JFrame) into an applet (JApplet), and I have seen a few "big steps":
    1�: make the class extends to JApplet instead of a JFrame
    2�: To replace the construction method by init ()
    3�: To comment the main method
    Is correct?, because I have some doubts that later I�ll explain
    Thanks

    I think in the init method (in a JApplet) I cannot call the super method. but my problem is how to change this? if in others files (in Files.java) I have calls to super metod, because thus it constructs a dialog box, asking for a file.
    In file Files.java I have a class called "Abort" (extends to JDialog) in whitch:
    /* class Files.java */
    class Abort extends JDialog
              boolean abort = true;
              JTextArea mensage = null;
              JButton acept = new JButton("Acept");
              JButton cancel = new JButton("Cancel");
              Abort(String nanemFile)
                   super(MainClassFile.mainWindow, " Attention!", true);
    /* clas Files.java */Please help

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

  • How to Serialize a JPanel which is inside a JApplet

    Hi..
    I have a JApplet where i have a JPanel which contains some JLabels and JTextFields,now i have to Serialize that full Panel so that i can retrived it later on with the labels and textfields placed in the same order,for that i tried serializing the full panel on to a file but it is giving me NotSerializeException,i dont know how to tackel it..
    public SaveTemplate(JPanel com) {
    try {
    ObjectOutputStream os=new ObjectOutputStream(new FileOutputStream("Temp1.temp"));
    os.writeObject(com);
    catch(Exception e) {
    e.printStackTrace();
    This is the code..plz help me with that..

    Actually its forming a Template which client will generate and that has to saved on the serverside..So what i thought that once when the client has designed a template,i can save the full template which is a panel into a file and later on when he want to open the template i just have to read the file and create an object of JPanel and add to the frame,so i dont need to apply much effort for that...But now serialization in Applet is giving problem.

  • Cannot access file from JApplet

    I have used the swingall.jar file with my JApplet for any
    version of IE. It gives one error
    i.e
    Cannot access file c:\prog\project
    I want to create a directory within c:\prog and also i want
    to write some files there. Pls help me.

    try this my friend!
    1.     Compile the applet
    2.     Create a JAR file
    3.     Generate Keys
    4.     Sign the JAR file
    5.     Export the Public Key Certificate
    6.     Import the Certificate as a Trusted Certificate
    7.     Create the policy file
    8.     Run the applet
    Susan
    Susan bundles the applet executable in a JAR file, signs the JAR file, and exports the public key certificate.
    1.     Compile the Applet
    In her working directory, Susan uses the javac command to compile the SignedAppletDemo.java class. The output from the javac command is the SignedAppletDemo.class.
    javac SignedAppletDemo.java
    2.     Make a JAR File
    Susan then makes the compiled SignedAppletDemo.class file into a JAR file. The -cvf option to the jar command creates a new archive (c), using verbose mode (v), and specifies the archive file name (f). The archive file name is SignedApplet.jar.
    jar cvf SignedApplet.jar SignedAppletDemo.class
    3.     Generate Keys
    Susan creates a keystore database named susanstore that has an entry for a newly generated public and private key pair with the public key in a certificate. A JAR file is signed with the private key of the creator of the JAR file and the signature is verified by the recipient of the JAR file with the public key in the pair. The certificate is a statement from the owner of the private key that the public key in the pair has a particular value so the person using the public key can be assured the public key is authentic. Public and private keys must already exist in the keystore database before jarsigner can be used to sign or verify the signature on a JAR file.
    In her working directory, Susan creates a keystore database and generates the keys:
    keytool -genkey -alias signFiles -keystore susanstore -keypass kpi135 -dname "cn=jones" -storepass ab987c
    This keytool -genkey command invocation generates a key pair that is identified by the alias signFiles. Subsequent keytool command invocations use this alias and the key password (-keypass kpi135) to access the private key in the generated pair.
    The generated key pair is stored in a keystore database called susanstore (-keystore susanstore) in the current directory, and accessed with the susanstore password (-storepass ab987c).
    The -dname "cn=jones" option specifies an X.500 Distinguished Name with a commonName (cn) value. X.500 Distinguished Names identify entities for X.509 certificates.
    You can view all keytool options and parameters by typing:
    keytool -help
    4.     Sign the JAR File
    JAR Signer is a command line tool for signing and verifying the signature on JAR files. In her working directory, Susan uses jarsigner to make a signed copy of the SignedApplet.jar file.
    jarsigner -keystore susanstore -storepass ab987c -keypass kpi135 -signedjar SSignedApplet.jar SignedApplet.jar signFiles
    The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.
    5.     Export the Public Key Certificate
    The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.
    The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.
    5: Export the Public Key Certificate
    The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.
    In her working directory, Susan uses keytool to copy the certificate from susanstore to a file named SusanJones.cer as follows:
    keytool -export -keystore susanstore -storepass ab987c -alias signFiles -file SusanJones.cer
    Ray
    Ray receives the JAR file from Susan, imports the certificate, creates a policy file granting the applet access, and runs the applet.
    6.     Import Certificate as a Trusted Certificate
    Ray has received SSignedApplet.jar and SusanJones.cer from Susan. He puts them in his home directory. Ray must now create a keystore database (raystore) and import the certificate into it. Ray uses keytool in his home directory /home/ray to import the certificate:
    keytool -import -alias susan -file SusanJones.cer -keystore raystore -storepass abcdefgh
    7.     Create the Policy File
    The policy file grants the SSignedApplet.jar file signed by the alias susan permission to create newfile (and no other file) in the user's home directory.
    Ray creates the policy file in his home directory using either policytool or an ASCII editor.
    keystore "/home/ray/raystore";
    // A sample policy file that lets a JavaTM program
    // create newfile in user's home directory
    // Satya N Dodda
    grant SignedBy "susan"
         permission java.security.AllPermission;
    8.     Run the Applet in Applet Viewer
    Applet Viewer connects to the HTML documents and resources specified in the call to appletviewer, and displays the applet in its own window. To run the example, Ray copies the signed JAR file and HTML file to /home/aURL/public_html and invokes Applet viewer from his home directory as follows:
    Html code :
    </body>
    </html>
    <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="600" height="400" align="middle"
    codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,1,2">
    <PARAM NAME="code" VALUE="SignedAppletDemo.class">
    <PARAM NAME="archive" VALUE="SSignedApplet.jar">
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    </OBJECT>
    </body>
    </html>
    appletviewer -J-Djava.security.policy=Write.jp
    http://aURL.com/SignedApplet.html
    Note: Type everything on one line and put a space after Write.jp
    The -J-Djava.security.policy=Write.jp option tells Applet Viewer to run the applet referenced in the SignedApplet.html file with the Write.jp policy file.
    Note: The Policy file can be stored on a server and specified in the appletviewer invocation as a URL.
    9.     Run the Applet in Browser
    Download JRE 1.3 from Javasoft
    save this to write.jp
    keystore "/home/ray/raystore";
    // A sample policy file that lets a JavaTM program
    // create newfile in user's home directory
    // Satya N Dodda
    grant {
    permission java.security.AllPermission;
    save this to signedAppletDemo.java
    * File: @(#)SignedAppletDemo.java     1.1
    * Comment:     Signed Applet Demo
    * @(#)author: Satya Dodda
    * @(#)version: 1.1
    * @(#)date: 98/10/01
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.io.*;
    import java.awt.Color;
    * A simple Signed Applet Demo
    public class SignedAppletDemo extends Applet {
    public String test() {
    setBackground(Color.white);
         System.out.println(System.getProperty("user.home"));
         String fileName = System.getProperty("user.home") +
                        System.getProperty("file.separator") +
                        "newfile";
         String msg = "This message was written by a signed applet!!!\n";
         String s ;
         try {
         FileWriter fos = new FileWriter(fileName);
         fos.write(msg, 0, msg.length());
         fos.close();
         s = new String("Successfully created file :" + fileName);
         } catch (Exception e) {
         System.out.println("Exception e = " + e);
         e.printStackTrace();
         s = new String("Unable to create file : " + fileName);
         return s;
    public void paint(Graphics g) {
    g.setColor(Color.blue);
    g.drawString("Signed Applet Demo", 120, 50);
    g.setColor(Color.magenta);
    g.drawString(test(), 50, 100);

  • Problem with the MenuBar and how can i delete a own component out of the storage

    Hello,
    I opened this thread in the category "Flex Builder 2", but
    under this category my questions fit better.
    I have a problem with the MenuBar and a question to delete a
    component out of storage.
    1. We have implemented the MenuBar, which was filled
    dynamically with XML data.
    Sporadically it will appear following fault, if we "mousover"
    the root layer.
    RangeError: Error #2006: Der angegebene Index liegt
    außerhalb des zulässigen Bereichs.
    at flash.display::DisplayObjectContainer/addChildAt()
    at mx.managers::SystemManager/
    http://www.adobe.com/2006/flex/mx/internal::rawChildren_addChildAt()
    at mx.managers::SystemManager/addChild()
    at mx.managers::PopUpManager$/addPopUp()
    at mx.controls::Menu/show()
    at mx.controls::MenuBar/::showMenu()
    at mx.controls::MenuBar/::mouseOverHandler()
    Here a abrid ged version of our XML to create the MenuBar:
    <Menuebar>
    <menu label="Artikel">
    <menu label="Artikel anlegen" data="new_article" />
    <menu label="Artikel bearbeiten" data="edit_article" />
    <menu label="Verpackung">
    <menu label="Verpackung anlegen" data="new_package" />
    <menu label="Verpackung bearbeiten" data="edit_package"
    />
    </menu>
    <menu label="Materialgruppe">
    <menu label="Materialgruppe anlegen"
    data="new_materialgroup" />
    <menu label="Materialgruppe bearbeiten"
    data="edit_materialgroup" />
    </menu>
    </menu>
    </Menuebar>
    It is a well-formed XML.
    2. Delete a component out of storage
    We have some own components (basically forms), which will be
    created and shown by an construct e.g.
    var myComponent : T_Component = new T_Component ;
    this.addChild(myComponent)
    Some of our forms will be created in an popup. On every call
    of the popup, we lost 5 mb or more, all childs on the windows will
    be removed by formname.removeAllChild();
    What cann we do, that the garbage collector will dispose this
    objects.
    Is there a way to show all objects with references (NOT
    NULL)?
    I have read in the Flex Help, that
    this.removeChild(myComponent) not delete the form and/or object out
    of the storage.
    Rather the object must be destroyed.
    It is sufficient to call delete(myComponent) about remove
    this object out of the storage as the case may be that the
    garbage-collector remove this object at any time?
    Or how can I destroy a component correctly. What happens with
    the widgets on this component e.g. input fields or datagrids?
    Are they also being deleted?
    Thanks for your help.
    Matze

    If you mena the "photo Library" then you cannot delete it.
    This is how iphone handles photos.  There are not two copies.  There a re simply two places from which to access the same photos.  ALL photos synced to iphone can be accessed via Photo Library.  Those same pics can be accessed via their individual folder.

Maybe you are looking for