What is wrong with the code II?

The code below did not display "test" as expected. Why and how
to fix it? Thanks.
import java.awt.*;
import javax.swing.*;
public class component extends JFrame
public component()
setTitle("add component test");
Container c = getContentPane();
ComboBoxTest cc = new ComboBoxTest("test");
c.add(cc);
setSize(200, 200);
setLocation(400, 300);
public static void main(String [] args)
component c = new component();
c.show();
class ComboBoxTest extends Component
public ComboBoxTest(String s)
a = new Label(s);
private Label a;

The code below did not display "test" as expected. Why
and how
to fix it? Thanks.I assume you mean the Label that has the text, test. If that's right, there isn't any code in ComboBoxTest that causes the Label to be displayed. I think you should extend something like JPanel instead of Component and add a JLabel to the JPanel.

Similar Messages

  • What's wrong with the code?

    public void run()
    try
    {     for(;;)
         mgr = (RTPManager)RTPManager.newInstance();
         mgr.addSessionListener(this);
         mgr.addReceiveStreamListener(this);
         try{  /*****port1 = port2 = 29261, which port is only used in here
         localAddr = new SessionAddress(InetAddress.getLocalHost(), port1);
         destAddr = new SessionAddress(ipAddr, port2);
         }catch(Exception e)
              System.out.println(e + " 4");
         try{
         mgr.initialize(localAddr);
         }catch(Exception e)
         System.out.println(e + " 5");
         //set buffer
         bc = (BufferControl)mgr.getControl("javax.media.control.BufferControl");
         if (bc != null)
         bc.setBufferLength(20);
         try{
              mgr.addTarget(destAddr);
         }catch(Exception e)
         System.out.println(e + " 2");
    catch(Exception e)
         System.out.println(e+ " 3");
    the error when i run the code is like that:
    javax.media.rtp.InvalidSessionAddressException: Can't open local data port: 29261
    5
    java.io.IOException: Address already in use: Cannot bind 2
    which means there is error in :
    mgr.initialize(localAddr);
    mgr.addTarget(destAddr);
    But i don't know what's wrong with the code,
    can any one help me?

    I do not find any problem using the same ports for local and destination address with several unicasts. My problems are others.
    But note that the error is even at constructing the localAddress, I mean before trying the destinationAddress. Thus the reason cannot be the former is already in use. In fact I think the later belongs to a remote hosts. Likely, it is trying to access the destinationAddress through the localAddress, but this has not been constructed properly.

  • Red highlight next to code in dreamweaver. What is wrong with the code and is it affecting the websi

    What is wrong with the code and is it affecting the website?

    Line 107 looks dodgy to me and it won't have any effect on your code.  However, it is a good idea to post a complete link to your CSS for us to see it in full and to validate it using external tools.  In fact, you could validate the CSS (and HTML) yourself..
    <http://jigsaw.w3.org/css-validator/>
    Good luck.

  • I'm trying to add the system date with a Label. What is wrong with the code

    import java.util.*;
    import javax.swing.*;
    public class CurrentDateApplet extends JApplet
         Calendar currentCalendar = Calendar.getInstance();
         JLabel dateLabel = new JLabel();
         JPanel mainPanel = new JPanel();
         int dayInteger = currentCalendar.get(Calendar.DATE);
         int monthInteger = currentCalendar.get(Calendar.MONTH)+1;
         int yearInteger = currentCalendar.get(Calendar.YEAR);
         public void init()
              mainPanel.add(dateLabel);
              setContentPane(mainPanel);
              dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
                        (Calendar.MINUTE);
    }

    As for what's wrong with the code, it would be easier if you said: it doesn't show the date (it does this instead), it doesn't compile (I get this message) etc.
    Anyway I'll assume you want to display the time in a label...
    dateLabel.append(currentCalendar.get(Calendar.HOUR) + currentCalendar.get
    (Calendar.MINUTE);This won't compile: the parentheses are mismatched, and there is simply no such thing as append(). So we could trydateLabel.setText("" + currentCalendar.get(Calendar.HOUR) + currentCalendar.get(Calendar.MINUTE));This wroks, but looks pretty nasty and it's not how you are supposed to format dates and times. Here's the unofficial party line, nicked from one of jverd's posts:
    Calculating Java dates: Take the time to learn how to create and use dates
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format
    From those links you should be able to find those applicable to times like this: http://www.exampledepot.com/egs/java.text/FormatTime.html
    Using this approach you would end up with something like:import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class CurrentDateApplet extends JApplet
        private Date date;
        private JLabel timeLabel;
        private JPanel mainPanel;
        public void init()
            mainPanel = new JPanel();
            timeLabel = new JLabel();
            mainPanel.add(timeLabel);
            setContentPane(mainPanel);
            date = new Date();
            Format formatter = new SimpleDateFormat("HH:ss a");
            timeLabel.setText(formatter.format(date));
    }

  • What is wrong with the code? (JOptionpane)

    I tried to run the program "AddingNumbers.java", but i always get error message, can anyone tells me what is wrong?
    Here is the code:
    import javax.swing.JOptionpane;     //import class JOptionpane
    public class Addition {
    public static void main( String args[])
         String firstNumber, secondNumber;
         int number1, number2, sum;
         firstNumber =
         JOptionpane.showInputDialog( "Enter first integer");
         secondNumber =
         JOptionpane.showInputDialog( "Enter second integer");
         number1 = Integer.parseInt( firstNumber);
         number2 = Integer.parseInt( secondNumber);
         sum = number1 + number2;
         JOptionpane.showMessageDialog(
         null, "The sum is " + sum, "Results",
         JOptionpane.PLAIN_MESSAGE );
         System.exit( 0 );
    The error messages are:
    import javax.swing.JOptionpane; //import class JOptionpane
    ^
    AddingNumbers.java:12: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.showInputDialog( "Enter first integer");
    ^
    AddingNumbers.java:15: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.showInputDialog( "Enter second integer");
    ^
    AddingNumbers.java:24: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.PLAIN_MESSAGE );
    ^
    AddingNumbers.java:22: cannot resolve symbol
    symbol : variable JOptionpane
    location: class Addition
    JOptionpane.showMessageDialog(
    ^
    6 errors
    Thanks.

    Hi, noah.w: can you help me for this code? it has error, too.
    the code:
    import javax.swing.JOptionPane;
    public class Comparison {
    public static void main( String args[])
         String      firstNumber,
              secondNumber
              result;
         int number1,
         number2;
         firstNumber =
         JOptionPane.showInputDialog( "Enter first integer");
         secondNumber =
         JOptionPane.showInputDialog( "Enter second integer");
         number1 = Integer.parseInt( firstNumber);
         number2 = Integer.parseInt( secondNumber);
         result = " ";
         if (number1 == number2 )
         result = result + number1 + " == " + number2;
         if (number1 != number2 )
         result = result + number1 + " != " + number2;
         if (number1 < number2 )
         result = result + "\n" + number1 + " < " + number2;
         if (number1 > number2 )
         result = result + "\n" + number1 + " > " + number2;
         if (number1 <= number2 )
         result = result + "\n" + number1 + " <= " + number2;
         if (number1 >= number2 )
         result = result + "\n" + number1 + " >= " + number2;
         JOptionPane.showMessageDialog(
         null, result, "Comparison Results",
         JOptionPane.INFORMATION_MESSAGE );
         System.exit( 0 );
    the error is:
    result = result + "\n" + number1 + " <= " + number2;
    ^
    Comparison.java:40: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    result = result + "\n" + number1 + " <= " + number2;
    ^
    Comparison.java:43: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    result = result + "\n" + number1 + " >= " + number2;
    ^
    Comparison.java:43: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    result = result + "\n" + number1 + " >= " + number2;
    ^
    Comparison.java:46: cannot resolve symbol
    symbol : variable result
    location: class Comparison
    null, result, "Comparison Results",
    ^
    15 errors
    How can i get the full screen of the messages? the DOS always shows the end part of the screen and i can't go back to take look the begainning of the errors.
    Thanks again.

  • Still trying to center the text of the jTextP. What is wrong with the code?

    The Code:
    JTextPane jTextPane1 = new JTextPane();
    MutableAttributeSet mas;
    mas=new SimpleAttributeSet();
    StyleConstants.setAlignment (mas, StyleConstants.ALIGN_RIGHT);
    jTextPane1.setCharacterAttributes(mas,false);
    jTextPane1.setText("message");
    The code doesn't align the text.
    Please HELP MEEEEEE
    Thanks.

    I've found the solution!!!!!!!!!!!!!!!!!!!!!
    insted of:
    jTextPane1.setCharacterAttributes(mas,true);
    you have to use:
    jTextPane1.setParagraphAttributes(mas,true);
    yuhuuuuuuuuuuuuuuuuuuuuuu!!!!!!!

  • What is wrong with the code?

    This is another example of an applet not working. How can i fix it?
    import java.awt.*;
    public class BurmaShave extends java.applet.Applet
         implements Runnable {
         CardLayout card = new CardLayout();
         Label[] lab = new Label[6];
         int current = 0;
         Thread runner;
         public void start() {
              if (runner == null) {
                   runner = new Thread(this);
                   runner.start();
         public void stop() {
              runner = null;
         public void init() {
              lab[0] = new Label("The Kotinon.. ");
              lab[1] = new Label("The honorable prize! ");
              setLayout(card);
              for (int i = 0; i < 3; i++)
                   add("Card " + i, lab[i] );
         public void run() {
              Thread thisThread = Thread.currentThread();
              while (runner == thisThread) {
                   card.show ( this , "Card " + current ) ;
                   current++;
                   if (current > 2)
                        current = 0;
                   repaint();
                   try {
                        Thread.sleep(2000);
                   } catch (InterruptedException e) { }
    Thanks.

    Ther are two mistakes.
    1. add(..., label)
    your label is of type array
    add(...,label)
    2. for (....; i < 3;...)
    you have two labels initialized label[0], label[1], if i becames 3, you get a nullpointerexception
    for (...; i < 2;...)
    here is the correct code
    public void init() {
    lab[0] = new Label("The Kotinon.. ");
    lab[1] = new Label("The honorable prize! ");
    setLayout(card);
    for (int i = 0; i < 2; i++)
    add("Card " + i, lab[i] );
    Aurelius

  • What's wrong with my code for comparing date retreived from db and sysdate?

    Hi all,
    I need to retrive date from the DB and compare it to system date.i have posted the code below.i get java.sql.SQL Exception:Io exception:Socket closed.
    What's wrong with the code?please help me.Thanks in advance.
    public boolean date() throws IOException, SQLException {
    Connection con1;
    long millis = System.currentTimeMillis();
    Timestamp timestamp = new java.sql.Timestamp(millis);
    ResultSet rs4 = null;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    con = DriverManager.getConnection(
    "jdbc:oracle:thin:@abc:1605:xyz",
    "cdf", "cdf");
    Statement stmt_exp = con.createStatement();
    rs4 = stmt_exp.executeQuery("SELECT DATE FROM TABLE_NAME")
    while (rs4.next()) {
    Timestamp timestamp2 = rs4.getTimestamp("expire_date");
    con1.close();
    catch (Exception e)
    e.printStackTrace();
    finally
    //ResultSet rs4 = null;
    //Timestamp timestamp2;
    Timestamp timestamp2 = rs4.getTimestamp("expire_date");
    if (timestamp2.compareTo(timestamp) < 0)  //sysdate < exp date
    return true;
    } else {
    return false;
    }

    Didn't you understand what BalusC said? You're closing the connection and then trying to use the ResultSet. The ResultSet will be closed when you close the connection so you can't use it anymore.
    You should close the connection last thing in your code, probably in a finally. And after you close your ResultSet and Statement.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • What's wrong with the following code?

    What's wrong with the following code?
    Circle cir1;
    double rad = cir1.radius

    The circle Object was never instantiated.
    In other words, you have set a declaring of a Circle, but it has not been created in memory yet.
    You will create it using the " = new Circle( PARAMETERS_HERE ); "
    Or some other method that returns a circle.

  • What is wrong with the idl code generated by packager.exe?

    Hello everybody,
    I am trying to figure out what is wrong with the idl code generated by packager.exe. In the evaluation for the bug posted at http://developer.java.sun.com/developer/bugParade/bugs/4964563.html it says that the IDispatch interface is not exposed correctly and thus early binding of java objects is not possible using the current activex bridge implementation.
    As I am no idl expert I have no idea what that means. However, I managed to dig out the idl code generated by packager.exe for the following example bean:
    package test;
    public class MyBean
         protected int value;
         public MyBean()
         public void setMyValue(int _value)
              value = _value;
         public int getMyValue()
              return value;
         public MyBean getSelfReference()
              return this;
    }The corresponding idl code generated by packager.exe is
    uuid(81B0BF63-2A55-11D8-A73E-000475EBF021),
    version(1.0)
    library MyBean
    importlib("Stdole2.tlb");
    dispinterface MyBeanSource;
    dispinterface MyBeanDispatch;
    uuid(81B0BF64-2A55-11D8-A73E-000475EBF021),
    version(1.0)
    dispinterface MyBeanSource {
    properties:
    methods:
    uuid(81B0BF65-2A55-11D8-A73E-000475EBF021),
    version(1.0)
    dispinterface MyBeanDispatch {
    properties:
    [id(4097)]
    int myValue;
    methods:
    [id(32768)]
    VARIANT_BOOL equals(IDispatch* arg0);
    [id(32769)]
    IDispatch* getClass();
    [id(32770)]
    int getMyValue();
    [id(32771)]
    IDispatch* getSelfReference();
    [id(32772)]
    int hashCode();
    [id(32773)]
    void notify();
    [id(32774)]
    void notifyAll();
    [id(32775)]
    void setMyValue(int arg0);
    [id(32776)]
    BSTR toString();
    [id(32779)]
    VARIANT wait([optional] VARIANT var0, [optional] VARIANT var1);
    uuid(81B0BF62-2A55-11D8-A73E-000475EBF021),
    version(1.0)
    coclass MyBean {
    [default, source] dispinterface MyBeanSource;
    [default] dispinterface MyBeanDispatch;
    };Does anyone know what is wrong with this code and maybe how to fix the idl code? Generating the dll should then be easy (I already tried several variations of the idl code but as my idl knowledge is limited it didn't really do what I wanted).

    Then the question is why it does work with visual controls (even if you set them to non-visible)?

  • Whats wrong with the code?????

    Hi All
    Pls can anyone help me, what is wrong with the below code, when ever i tried giving 10 digit number to chk out whether it is prime or not it is giving an NumberFormatException to me, pls can anyone help me...
    class PrimeNo{
    public static void main(String args[])
    int a = Integer.parseInt(args[0]);
    int count=0;
    for(int i=2;i<a;i++){
    if(a%i==0)
    System.out.println(a+" is not a Prime Number");
    count = 1;
    break;
    if(count==0)
    System.out.println(a+" is a Prime Number");
    Thnx and rgrds
    Badri

    Just curious, since this has already been answered, but to simplify code, would it be possible to set it so that if the value is not a prime number, just do the value like so:
    if (//code determines it is prime)
    System.out.println ("prime number");
    else
    prime = !prime;
    if(!prime)
    System.out.println ("not a prime number");not really code there, more pseudocode, but you get my drift. Would this make sense to do?

  • What is wrong with this code? on(release) gotoAndPlay("2")'{'

    Please could someone tell me what is wrong with this code - on(release)
    gotoAndPlay("2")'{'
    this is the error that comes up and i have tried changing it but it is not working
    **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 2: '{' expected
         gotoAndPlay("2")'{'
    Total ActionScript Errors: 1 Reported Errors: 1
    Thanks

    If you have a frame labelled "2" then it should be:
    on (release) {
        this._parent.gotoAndPlay("2");
    or other wise just the following to go to frame 2:
    on (release) {
         this._parent.gotoAndPlay(2);
    You just had a missing curly bracket...

  • I can't figure out what's wrong with this code

    First i want this program to allow me to enter a number with the EasyReader class and depending on the number entered it will show that specific line of this peom:
    One two buckle your shoe
    Three four shut the door
    Five six pick up sticks
    Seven eight lay them straight
    Nine ten this is the end.
    The error message i got was an illegal start of expression. I can't figure out why it is giving me this error because i have if (n = 1) || (n = 2) statements. My code is:
    public class PoemSeventeen
    public static void main(String[] args)
    EasyReader console = new EasyReader();
    System.out.println("Enter a number for the poem (0 to quit): ");
    int n = console.readInt();
    if (n = 1) || (n = 2)
    System.out.println("One, two, buckle your shoe");
    else if (n = 3) || (n = 4)
    System.out.println("Three, four, shut the door");
    else if (n = 5) || (n = 6)
    System.out.println("Five, six, pick up sticks");
    else if (n = 7) || (n = 8)
    System.out.println("Seven, eight, lay them straight");
    else if (n = 9) || (n = 10)
    System.out.println("Nine, ten, this is the end");
    else if (n = 0)
    System.out.println("You may exit now");
    else
    System.out.println("Put in a number between 0 and 10");
    I messed around with a few other thing because i had some weird errors before but now i have narrowed it down to just this 1 error.
    The EasyReader class code:
    // package com.skylit.io;
    import java.io.*;
    * @author Gary Litvin
    * @version 1.2, 5/30/02
    * Written as part of
    * <i>Java Methods: An Introduction to Object-Oriented Programming</i>
    * (Skylight Publishing 2001, ISBN 0-9654853-7-4)
    * and
    * <i>Java Methods AB: Data Structures</i>
    * (Skylight Publishing 2003, ISBN 0-9654853-1-5)
    * EasyReader provides simple methods for reading the console and
    * for opening and reading text files. All exceptions are handled
    * inside the class and are hidden from the user.
    * <xmp>
    * Example:
    * =======
    * EasyReader console = new EasyReader();
    * System.out.print("Enter input file name: ");
    * String fileName = console.readLine();
    * EasyReader inFile = new EasyReader(fileName);
    * if (inFile.bad())
    * System.err.println("Can't open " + fileName);
    * System.exit(1);
    * String firstLine = inFile.readLine();
    * if (!inFile.eof()) // or: if (firstLine != null)
    * System.out.println("The first line is : " + firstLine);
    * System.out.print("Enter the maximum number of integers to read: ");
    * int maxCount = console.readInt();
    * int k, count = 0;
    * while (count < maxCount && !inFile.eof())
    * k = inFile.readInt();
    * if (!inFile.eof())
    * // process or store this number
    * count++;
    * inFile.close(); // optional
    * System.out.println(count + " numbers read");
    * </xmp>
    public class EasyReader
    protected String myFileName;
    protected BufferedReader myInFile;
    protected int myErrorFlags = 0;
    protected static final int OPENERROR = 0x0001;
    protected static final int CLOSEERROR = 0x0002;
    protected static final int READERROR = 0x0004;
    protected static final int EOF = 0x0100;
    * Constructor. Prepares console (System.in) for reading
    public EasyReader()
    myFileName = null;
    myErrorFlags = 0;
    myInFile = new BufferedReader(
    new InputStreamReader(System.in), 128);
    * Constructor. opens a file for reading
    * @param fileName the name or pathname of the file
    public EasyReader(String fileName)
    myFileName = fileName;
    myErrorFlags = 0;
    try
    myInFile = new BufferedReader(new FileReader(fileName), 1024);
    catch (FileNotFoundException e)
    myErrorFlags |= OPENERROR;
    myFileName = null;
    * Closes the file
    public void close()
    if (myFileName == null)
    return;
    try
    myInFile.close();
    catch (IOException e)
    System.err.println("Error closing " + myFileName + "\n");
    myErrorFlags |= CLOSEERROR;
    * Checks the status of the file
    * @return true if en error occurred opening or reading the file,
    * false otherwise
    public boolean bad()
    return myErrorFlags != 0;
    * Checks the EOF status of the file
    * @return true if EOF was encountered in the previous read
    * operation, false otherwise
    public boolean eof()
    return (myErrorFlags & EOF) != 0;
    private boolean ready() throws IOException
    return myFileName == null || myInFile.ready();
    * Reads the next character from a file (any character including
    * a space or a newline character).
    * @return character read or <code>null</code> character
    * (Unicode 0) if trying to read beyond the EOF
    public char readChar()
    char ch = '\u0000';
    try
    if (ready())
    ch = (char)myInFile.read();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (ch == '\u0000')
    myErrorFlags |= EOF;
    return ch;
    * Reads from the current position in the file up to and including
    * the next newline character. The newline character is thrown away
    * @return the read string (excluding the newline character) or
    * null if trying to read beyond the EOF
    public String readLine()
    String s = null;
    try
    s = myInFile.readLine();
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    if (s == null)
    myErrorFlags |= EOF;
    return s;
    * Skips whitespace and reads the next word (a string of consecutive
    * non-whitespace characters (up to but excluding the next space,
    * newline, etc.)
    * @return the read string or null if trying to read beyond the EOF
    public String readWord()
    StringBuffer buffer = new StringBuffer(128);
    char ch = ' ';
    int count = 0;
    String s = null;
    try
    while (ready() && Character.isWhitespace(ch))
    ch = (char)myInFile.read();
    while (ready() && !Character.isWhitespace(ch))
    count++;
    buffer.append(ch);
    myInFile.mark(1);
    ch = (char)myInFile.read();
    if (count > 0)
    myInFile.reset();
    s = buffer.toString();
    else
    myErrorFlags |= EOF;
    catch (IOException e)
    if (myFileName != null)
    System.err.println("Error reading " + myFileName + "\n");
    myErrorFlags |= READERROR;
    return s;
    * Reads the next integer (without validating its format)
    * @return the integer read or 0 if trying to read beyond the EOF
    public int readInt()
    String s = readWord();
    if (s != null)
    return Integer.parseInt(s);
    else
    return 0;
    * Reads the next double (without validating its format)
    * @return the number read or 0 if trying to read beyond the EOF
    public double readDouble()
    String s = readWord();
    if (s != null)
    return Double.parseDouble(s);
    // in Java 1, use: return Double.valueOf(s).doubleValue();
    else
    return 0.0;
    Can anybody please tell me what's wrong with this code? Thanks

    String[] message = {
        "One, two, buckle your shoe",
        "One, two, buckle your shoe",
        "Three, four, shut the door",
        "Three, four, shut the door",
        "Five, six, pick up sticks",
        "Five, six, pick up sticks",
        "Seven, eight, lay them straight",
        "Seven, eight, lay them straight",
        "Nine, ten, this is the end",
        "Nine, ten, this is the end"
    if(n>0)
        System.out.println(message[n]);
    else
        System.exit(0);

  • [b]Does anybody know what is wrong with my code[/b]

    I cannot see what is wrong with this code but i can't get it to compile. when i try to compile it i get the
    "Exception in thread "main" java.lang.NoClassDefFoundError:
    Is this a problem with compiling or is it a code error?
    Here is my code
    public class IntCalc{
         int value;
         public IntCalc(){
              value = 0;
         public void add(int number)     {
              value = value + number;
         public void subtract(int number){
              value = value - number;
         public int getValue()     {
              return value;
    Message was edited by:
    SHIFTER

    Youd don't have a class file. Compile it first then run it. If your compiler isnt making the .class file tell me and ill give you a link to a realy good java compiler.

  • JScrollPane, what is wrong with my code?

    Hi, I appreciated if you helped me(perhaps by trying it out yourself?)
    I wanted my JScrollPane to display what is drawn on my canvas (which may be large)by scrolling, but it says it doesn't need any vertical and horizontal scroll bars. Here is the code that has this effect
    import javax.swing.*;
    import java.awt.*;
    public class WhatsWrong extends JApplet{
    public void init(){
    Container appletCont = getContentPane();
    appletCont.setLayout(new BorderLayout());
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(new LargeCanvas(),BorderLayout.CENTER);
    int ver = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int hor = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(p,ver,hor);
    appletCont.add(jsp,BorderLayout.CENTER);
    class LargeCanvas extends Canvas{
    public LargeCanvas(){
    super();
    setBackground(Color.white);
    public void paint(Graphics g){
    g.drawRect(50,50,700,700);
    and the html code:
    <html>
    <body>
    <applet code="WhatsWrong" width = 300 height = 250>
    </applet>
    </body>
    </html>
    What shall I do?
    Thanks in advance.

    What is wrong with your code is that your class, LargeCanvas must implement the Scrollable interface in order to be scrolled by a JScrollPane.
    A comment regarding your use of Canvas and Swing components: The Java Tutorial recommends that you extend JPanel to do custom painting. Canvas is what they call a "heavyweight" component and they recommend not to mix lightweight (Swing) components and heavyweight components.
    There is a lot more information on custom painting on the Java Tutorial in the Lesson "Creating a GUI with Swing.

Maybe you are looking for

  • Thunderbolt drive ejects when computer asleep

    This is an issue with a 3.5 GHz Core i7 iMac running 10.9.4 and a Lacie 5 disc Thunderbolt external with a RAID 0 (3x 2TB drives) and a RAID 1 (2x mirrored 2TB drives). At least once a week, and sometimes more, I wake my computer from sleep to discov

  • Sql to create logical partitions

    Oracle: 10.2.0.5 I am working with another group and they are pulling data from one of the databases I work on. They are using what they call 'logical partitions'. Basically it is a sql statement with a MOD function in the where clause. select * from

  • How can I watch the lyrics in my ipad?

    Hello! I can see the lyrics of my songs in iTunes and iPhone but not in my ipad. What can I do? Thanks, Juan

  • Please help.. My phone locked!!

    This is a stupid question but my friend bought iphone 4 for me from USA. but it doesn't work in my country (Thailand) i mean it locked.. How can i do the factory unlock in my country ?? and one question.. I try to do the case program app from my phon

  • Intel (HD) graphics issue when trying to use "Stellarium" on Satellite C660

    Stellarium (a free application for astronomie) works w/o any problem on many computers of my astronomie club but impossible to use it on my Toshiba Satellite C660-226. No problem during installation but nothing appends when I launch the program. I ru