Public void init() {

public void init() {
imgMap = getImage(getCodeBase(), ("cardiff3.jpg"));
}//init
when i load this image in an applet over the net the downloaded parts of the image only become visible when i click the mouse(mouseClicked() happens to call repaint().
how can i get the image to load without having to click the mouse all the time. is there an automatic way of calling repaint() repeatedly?

just a thought...
public void init() {
imgMap = getImage(getCodeBase(), ("cardiff3.jpg"));
if (imgMap != null){
repaint();
}//init

Similar Messages

  • Difference between public void, private void and public string

    Hi everyone,
    My 1st question is how do you know when to use public void, private void and public string? I am mightily cofuse with this.
    2ndly, Can anybody explain to me on following code snippet:
    Traceback B0;//the starting point  of Traceback
    // Traceback objects
    abstract class Traceback {
      int i, j;                     // absolute coordinates
    // Traceback2 objects for simple gap costs
    class Traceback2 extends Traceback {
      public Traceback2(int i, int j)
      { this.i = i; this.j = j; }
    }And using the code above is the following allowed:
    B[0] = new Traceback2(i-1, 0);
    Any replies much appreciated. Thank you.

    1)
    public and private are access modifiers,
    void and String return type declarations.
    2)
    It's called "inheritance", and "bad design" as well.
    You should read the tutorials, you know?

  • Difference between Public Void and Public Int

    I was wondering what the difference was between 'public void' and 'public int'?

    Yeah,
    Given package forumTest;
    public class ReturnVoid
         public int returnInt()
         public void returnVoid()
    }compiling using the 1.4.2 reference compiler produces the following result:
    $ javac -d classes/ src/forumTest/ReturnVoid.java
    src/forumTest/ReturnVoid.java:6: missing return statement
            ^
    1 error

  • Public void actionPerformed(ActionEvent e)

    public void actionPerformed(ActionEvent e)
            if(e.equals("north"))
                e.getSource().getClass(CLI);
        } hi i have a class called CLI which handles all the methods. i am reating a gui. i have created the buttons and layout and added actionlisteners to them. i am having trouble assigning the method north() whic is of type static void to the button.
    bassically when the button "north" is pressed i want to call the method North. i have been recommened to use the getSource() method from
    import java.util.EventObject;
    any ideas on where im going wrong?

    Forget getSource, assign a separate anonymous ActionListener to each button, that way when actionPerformed is called you already know which button was pressed.
    All you need to do (if you've put a handler method private void north() into your main class) is:
    northButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e)  {
             north();
      });(And, obviously, similarly for other buttons).
    This creates an instance of an anonymous inner class and connects the button to it so that the actionPerformed method is called when the button is pressed. That, in turn, calls north(); Because it's an inner class it can use the methods of the class it's contained in.

  • I want to know when the method "public void setName" is invoked?

    The jsp file contain the one which list below:
    <mt:hello name="foo"/>
    package com.acme.tag;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class HelloTag extends TagSupport
    private String name="";
    public HelloTag()
    super();
    � public void setName(String name) �
    � {                                                                    �
    � this.name=name; �
    � } �
    �_____________________________________________�
    public int doEndTag() throws javax.servlet.jsp.JspTagException
    try
    pageContext.getOut().write("Hello "+name+"!");
    catch(java.io.IOException e)
    throw new JspTagException("IO Error: " + e.getMessage());
    return EVAL_PAGE;
    }

    does the other method like :
    <b>public void setPageContext(PageContext PageContext)</b>
    and
    <b>public javax.servlet.jsp.tagext.Tag getParent()</b>
    is invoked like setName list above.
    Thanks!

  • How can i call the public void paint(Graphics g) method on click of button?

    Hello,
    I have done this before i know its got to do something with the repaint() method but can someone show me with and example and call the paint method using AWT in a frame not in an applet....
    Thank you very much.

    Thank You very Much.... You have cleared all my doubts.
    But my main objective is to display an image in an AWT Frame !!
    here is the code that i have been trying..
    import java.awt.*;
    import java.awt.event.*;
    public class check6 extends Panel
         Frame f;
         Image i;
         public check6()
              f = new Frame("Heading");
              f.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent e){
                        System.exit(0);
              final Button b1 = new Button("Submit");
              b1.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e){
                        repaint();
              i = getImage(getCodeBase(), "titanic.jpg");
              add(b1);
              setLayout(new FlowLayout(FlowLayout.LEFT));
              f.add(this);
              f.setSize(500,500);
              f.setVisible(true);
         public void paint(Graphics g)
              g.drawImage(i,10,10,this);
         public static void main(String args[])
              new check6();
    }

  • Question about public void characters(char []ch, int start, int length) thr

    Can anyone tell me how you would keep all the characters from within one pair of tags together each time characters() is called?
    the character() method doesn't read all the character data at once, and i would like to create a buffer of what it has read.
    thank you.

    I recommend using getNodeName and/or/combination
    with
    getNodeValue to get the strings.i have tried using a buffer, and i have got that to work!
    At long last I am seeing the string I would like to see as it is in the xml file!
    thank you for your help
    here is an example of my code:
    private boolean isDescription = false;
    StringBuffer sb = new StringBuffer();
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
         if(localName.equals("description")) {
              sb = new StringBuffer();
              isDescription = true;
    public void characters(char []ch, int start, int length) throws SAXException {
         if(isDescription == true) {
              String desc = new String(ch, start, length);
              sb.append(desc);
    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
         if(localName.equals("description")) {
              isDescription == false;
              System.out.println(sb.toString());
    }

  • JTree DnD Problem - public void drop(DropTargetDropEvent e)

    This method won't executed, can someone give me some ideas what the problem could be.
    After the following (simplified) method is called nothing happens.
    public void dragOver(DropTargetDragEvent e)
    e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE );
    How usually the void drop(DropTargetDropEvent e) method gets executetd ?
    thanks for answers...

    Ensure that you have initialised a DropTarget
    and implemented the DropTargetListener

  • RMI: swing: class ot interface expeted : public void

    PLease take look at the program and the error, i have underlined the area where error has occured...
    Thnk you
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.rmi.*;
    import java.net.*;
         public class appRMIcc extends Frame implements ActionListener{
               JLabel l;
               JTextField tf1,tf2;
               JButton b;
                    public appRMIcc(){
                         setLayout(new FlowLayout());
                         l = new JLabel("Enter the Credit Card number");
                         tf1 = new JTextField(30);
                         tf2 = new JTextField(30);
                         b = new JButton("Check the Card Number");
                         add(l);add(tf1);add(b);
                         add(tf2);
                         b.addActionListener(this);
                         public void actionPerformed(ActionEvent e){                          String cc = tf1.getText();
                              try{
                                   RMIccinterface robj;
                                   robj = (RMIccinterface) Naming.lookup("rmi://127.0.0.1/visagold");
                                   if(robj.isValid(cc)) tf2.setText(String.valueOf("Credit Card valid"));
                                   else
                                   tf2.setText(String.valueOf("Invalid Credit Card Number"));
                                   catch(Exception ex){
                                        System.out.println(ex);
               public static void main(String v[]){
                    appRMIcc dd = new appRMIcc();
                    dd.setSize(400,400);
                    dd.show();
    i got the following error, i ra the above program in the command line, it worked fine but applet is not working..
    --------------------Configuration: <Default>--------------------
    C:\j2sdk\bin\appRMIcc.java:28: 'class' or 'interface' expected
                                    public void actionPerformed(ActionEvent e){
                                           ^
    1 error
    Process completed.
         

    public appRMIcc(){
      setLayout(new FlowLayout());
      l = new JLabel("Enter the Credit Card number");
      tf1 = new JTextField(30);
      tf2 = new JTextField(30);
      b = new JButton("Check the Card Number");
      add(l);add(tf1);add(b);
      add(tf2);
      b.addActionListener(this);
    }If you say so...

  • Public void movePlayer

    I cant figure out what to write for my switch statement on this assignment,
    (25 spaced board game with 2 players, each taking turns rolling a die untill someone reaches 25)
    my method parameters for the movePlayer method are sapposed to be which player, (player1 or player2), moves as well as how many spaces out of 6 (rolled on the die). i am also sapposed to check if a winner can be identified in case 1 and case 2.
    i thought i was getting the hang of this but on this i'm at a total loss for ideas of how to do it,
    anyone have suggestions?
    public class GameBoard
            public static final int BOARD_LENGTH = 25;
         private int player1;
         private int player2;
         private int winner;
    public GameBoard(int player1State, int player2State)
              player1 = 0;
              player2 = 0;
              winner = 0;
              player1 = player1State;
              player2 = player2State;
    int player1State;
    int player2State;
    public int getBoardLength()
              return BOARD_LENGTH;
    public int getPlayer1State()
              return player1State;
    public int getPlayer2State()
              return player2State;
    int getWinner()
              return winner;
    public void resetBoard(int player1State, int player2State, int winner)
              player1State = 0;
              player2State = 0;
              winner = 0;
             // This method moves the specified player along
         // the game board a specified number of spaces.
         public void movePlayer( int spacesMoved, int playerMoved)
                 int spacesMoved;
                 int playerMoved;
              switch( playerMoved )
                   case 1:
                        // Your code goes here.
                   case 2:
                        // Your code goes here.
                   default:
                        System.out.println("Warning: Player " +  //Fill this in//
                                            + " does not exist!");
    }

    public class GameBoard
            public static final int BOARD_LENGTH = 25;
         private int player1;
         private int player2;
         private int winner;
    public GameBoard(int player1State, int player2State)
              player1 = 0;  // pointless! you reset its value 3 lines below
              player2 = 0;  // ditto
              winner = 0;
              player1 = player1State;
              player2 = player2State;
    int player1State;  // why do  you need a player1 variable as well as this one?
    int player2State;  // ditto
    public int getBoardLength()
              return BOARD_LENGTH;
    public int getPlayer1State()
              return player1State;
    public int getPlayer2State()
              return player2State;
    int getWinner()
              return winner;
    public void resetBoard(int player1State, int player2State, int winner)
              player1State = 0;
              player2State = 0;
              winner = 0;
             // This method moves the specified player along
         // the game board a specified number of spaces.
         public void movePlayer( int spacesMoved, int playerMoved)
                 int spacesMoved;  // pointless! You have a parameter with same name
                 int playerMoved;  // ditto
              switch( playerMoved )
                   case 1:
                        // Your code goes here.
                                   // presumably it is player1's turn so increase the player1 variable by number of spaces
                   case 2:
                        // Your code goes here.
                                    // ditto but for player2
                   default:
                        System.out.println("Warning: Player " +  //Fill this in//
                                            + " does not exist!");
    }See comments.

  • Public void drop(DropTargetDropEvent e)

    This method won't executed, can someone give me some ideas what the problem could be or when normaly this method gets called ?
    After the following (simplified) method is called nothing happens.
    public void dragOver(DropTargetDragEvent e)
    e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE );
    How usually the void drop(DropTargetDropEvent e) method gets executetd ?
    thanks for answers...

    Ensure that you have initialised a DropTarget
    and implemented the DropTargetListener

  • Public void getConfiguredList() { ....} //is the name correct

    hi,
    i have used the name in my project where i'm getting a list. actually the method will not return anything, but by that call i can get the list from some other notifier. here, is the method name getConfiguredList() with void return type correct?
    help!
    -karups

    yeah, that's correct.but, i might have implemented the method to directly return the value, but it takes longer time as the data is coming from server to the client. hence i used the notification mechanism, once the data is received, my calss will be informed with the data. here in my case after calling the method i'm doing nothing but waiting for the data to come.this way i release the thread lock,so the user won't get the feel of delay in response, coz he'll do any other operation in that time span. so, i guess, it,naming like this, makes sense in this particular situtation. pl. opine.

  • Code too large  for public void _jspService

    the file size is 820Kb.it was not getting compiled with a jasper compiler so i used a plain javac to try and compile and even that failed.Previously i had done the same for a 640k file and javac had worked fine but now it doesnt.Does even javac has a limit please feel free to suggest solutions which would help me to compile these files.Maybe memory settings please its urgent.

    There is no limit on the size of the source file.
    For auto-generated code you sometimes hit the size limitation on a method (64k bytes of bytecode).
    It is possible javac is running out of memory, tryjavac -J-Xmx128m

  • Init() method: private vs. public

    I have a question:
    What is the difference in defining your init() method in a servlet as private vs. public since it is automatically executed when the class is instantiated?
    thanks

    cbreneman,
    For future reference,
    public void foo() {
        method vailable to all
    protected void foo() {
        method vailable to pacakge
    private void Foo() {
        method vailable to this
    }You can do this:
    public String bar;
    protected String bar;
    private String bar;You cannot do this:
    private void Foo() {
        public String bar = "Oops!";
    }For an Applet, init() is inherited when you extend the Applet class. It must be overidden if you have work to do before your subclass becomes active. It is defined by the superclass as public and void. If you were to create an init() method that was private and returned a String, you might (the compiler will stop you if you try to define init() twice) have a different method, but you would not have overidden public void init(). If you tried something like private void init() the compiler would stop you:
    init() in FooBar cannot override init() in java.applet.Applet; attempting to assign weaker access privileges; was public
    private void init() {
    ^
    1 error
    Make sense?
    With servlets, the init() method is there for slightly different reasons and to be honest, I am not sure that you inherit it? I believe it acts as a special constructor? I don't write many servlets, so I'll shut up and let someone who does give a better answer.
    Hope this helps.

  • Applet has illegal start of expression at public VNCViewer() method{  )

    package viewer;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.Label;
    public class VNCViewer extends java.applet.Applet implements Runnable
      public static final String version = "4.1";
      public static final String about1 = "VNC Viewer Free Edition "+version;
      public static final String about2 = "Copyright (C) 2002-2005 RealVNC Ltd.";
      public static final String about3 = ("See http://www.realvnc.com for "+
                                           "information on VNC.");
      public static final String aboutText = about1+"\n"+about2+"\n"+about3;
      public static void main(String[] argv) {
        VNCViewer viewer = new VNCViewer(argv);
        viewer.start();
      public VNCViewer(String[] argv) {
        applet = false;
        // Override defaults with command-line options
        for (int i = 0; i < argv.length; i++) {
          if (argv.equalsIgnoreCase("-log")) {
    if (++i >= argv.length) usage();
    System.err.println("Log setting: "+argv[i]);
    rfb.LogWriter.setLogParams(argv[i]);
    continue;
    if (rfb.Configuration.setParam(argv[i]))
    continue;
    if (argv[i].charAt(0) == '-') {
    if (i+1 < argv.length) {
    if (rfb.Configuration.setParam(argv[i].substring(1), argv[i+1])) {
    i++;
    continue;
    usage();
    if (vncServerName.getValue() != null)
    usage();
    vncServerName.setParam(argv[i]);
    public static void usage() {
    String usage = ("\nusage: vncviewer [options/parameters] "+
    "[host:displayNum] [options/parameters]\n"+
    //" vncviewer [options/parameters] -listen [port] "+
    //"[options/parameters]\n"+
    "\n"+
    "Options:\n"+
    " -log <level> configure logging level\n"+
    "\n"+
    "Parameters can be turned on with -<param> or off with "+
    "-<param>=0\n"+
    "Parameters which take a value can be specified as "+
    "-<param> <value>\n"+
    "Other valid forms are <param>=<value> -<param>=<value> "+
    "--<param>=<value>\n"+
    "Parameter names are case-insensitive. The parameters "+
    "are:\n\n"+
    rfb.Configuration.listParams());
    //System.err.print(usage);
    //System.exit(1);
    //Illegal Start of Expression is here...
    public VNCViewer() {
    applet = true;
    firstApplet = true;
    public static void newViewer(VNCViewer oldViewer) {
    VNCViewer viewer = new VNCViewer();
    viewer.applet = oldViewer.applet;
    viewer.firstApplet = false;
    viewer.start();
    public void init() {
    vlog.debug("init called");
    setBackground(Color.white);
    logo = getImage(getDocumentBase(), "logo150x150.gif");
    public void start() {
    vlog.debug("start called");
    nViewers++;
    if (firstApplet) {
    alwaysShowServerDialog.setParam(true);
    rfb.Configuration.readAppletParams(this);
    String host = getCodeBase().getHost();
    if (vncServerName.getValue() == null && vncServerPort.getValue() != 0) {
    int port = vncServerPort.getValue();
    vncServerName.setParam(host + ((port >= 5900 && port <= 5999)
    ? (":"+(port-5900))
    : ("::"+port)));
    thread = new Thread(this);
    thread.start();
    public void paint(Graphics g) {
    g.drawImage(logo, 0, 0, this);
    int h = logo.getHeight(this)+20;
    g.drawString(about1, 0, h);
    h += g.getFontMetrics().getHeight();
    g.drawString(about2, 0, h);
    h += g.getFontMetrics().getHeight();
    g.drawString(about3, 0, h);
    public void run() {
    CConn cc = null;
    try {
    cc = new CConn(this);
    if (cc.init(null, vncServerName.getValue(),
    alwaysShowServerDialog.getValue())) {
    while (true)
    cc.processMsg();
    } catch (rdr.EndOfStream e) {
    vlog.info(e.toString());
    } catch (Exception e) {
    if (cc != null) cc.removeWindow();
    if (cc == null || !cc.shuttingDown) {
    e.printStackTrace();
    new MessageBox(e.toString());
    if (cc != null) cc.removeWindow();
    nViewers--;
    if (!applet && nViewers == 0) {
    System.exit(0);
    rfb.BoolParameter fastCopyRect
    = new rfb.BoolParameter("FastCopyRect",
    "Use fast CopyRect - turn this off if you get "+
    "screen corruption when copying from off-screen",
    true);
    rfb.BoolParameter useLocalCursor
    = new rfb.BoolParameter("UseLocalCursor",
    "Render the mouse cursor locally", true);
    rfb.BoolParameter autoSelect
    = new rfb.BoolParameter("AutoSelect",
    "Auto select pixel format and encoding", true);
    rfb.BoolParameter fullColour
    = new rfb.BoolParameter("FullColour",
    "Use full colour - otherwise 6-bit colour is used "+
    "until AutoSelect decides the link is fast enough",
    false);
    rfb.AliasParameter fullColor
    = new rfb.AliasParameter("FullColor", "Alias for FullColour", fullColour);
    rfb.StringParameter preferredEncoding
    = new rfb.StringParameter("PreferredEncoding",
    "Preferred encoding to use (ZRLE, hextile or"+
    " raw) - implies AutoSelect=0", null);
    rfb.BoolParameter viewOnly
    = new rfb.BoolParameter("ViewOnly", "Don't send any mouse or keyboard "+
    "events to the server", false);
    rfb.BoolParameter shared
    = new rfb.BoolParameter("Shared", "Don't disconnect other viewers upon "+
    "connection - share the desktop instead", false);
    rfb.BoolParameter acceptClipboard
    = new rfb.BoolParameter("AcceptClipboard",
    "Accept clipboard changes from the server", true);
    rfb.BoolParameter sendClipboard
    = new rfb.BoolParameter("SendClipboard",
    "Send clipboard changes to the server", true);
    rfb.BoolParameter alwaysShowServerDialog
    = new rfb.BoolParameter("AlwaysShowServerDialog",
    "Always show the server dialog even if a server "+
    "has been specified in an applet parameter or on "+
    "the command line", false);
    rfb.StringParameter vncServerName
    = new rfb.StringParameter("Server",
    "The VNC server <host>[:<dpyNum>] or "+
    "<host>::<port>", null);
    rfb.IntParameter vncServerPort
    = new rfb.IntParameter("Port",
    "The VNC server's port number, assuming it is on "+
    "the host from which the applet was downloaded", 0);
    Thread thread;
    boolean applet, firstApplet;
    Image logo;
    Label versionLabel;

    Looks like you have at least two missing "}"
    You have commented out one that you seem to need, right at the error.

Maybe you are looking for