Solved

simple question

Posted on 2004-09-14
5
165 Views
Last Modified: 2013-11-23
sir ,

 i mworking on mandrake linux on a
p3 system.


 i wrote a program for a creating a standalone window .That is it contains a main.

When i compile with javac , no error.
But when i try to run it using javac .Following errors



at java.lang.Class.for Name(class .java:native)

at java.lang.Class.for Name
(class:59)


what is this ? how can iavoid this ?
how can i create standalone window in java on linux platform ?


 
0
Comment
Question by:karana
5 Comments
 
LVL 21

Expert Comment

by:MogalManic
ID: 12061129
Is your classpath set correctly?
0
 
LVL 1

Expert Comment

by:raid999
ID: 12061332
Try this

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/** An applet that can also run as a standalone application */
public class StandaloneScribble extends Applet {
  /**
   * The main() method.  If this program is invoked as an application,
   * this method will create the necessary window, add the applet to it,

   
   * and call init(), below.  Note that Frame uses a PanelLayout by
   * default.              
   */
  public static void main(String[] args) {
    Frame f = new Frame();                     // Create a window
    Applet a = new StandaloneScribble();       // Create the applet panel
    f.add(a, "Center");                        // Add applet to window
    a.init();                                  // Initialize the applet
    f.setSize(400, 400);                       // Set the size of the
                                               // window
    f.show();                                  // Make the window visible
    f.addWindowListener(new WindowAdapter() {  // Handle window close
                                               // requests
      public void windowClosing(WindowEvent e) { System.exit(0); }
    });
  }
  /**
   * The init() method.  If the program is invoked as an applet, the
   * browser allocates screen space for it and calls this method to set
   * things up.
   */
  public void init() {
    // Define, instantiate and register a MouseListener object
    this.addMouseListener(new MouseAdapter() {
      public void mousePressed(MouseEvent e) {
        lastx = e.getX();
        lasty = e.getY();
      }
    });
    // Define, instantiate and register a MouseMotionListener object
    this.addMouseMotionListener(new MouseMotionAdapter() {
      public void mouseDragged(MouseEvent e) {
        Graphics g = getGraphics();
        int x = e.getX(), y = e.getY();
        g.setColor(Color.black);
        g.drawLine(lastx, lasty, x, y);
        lastx = x; lasty = y;
      }
    });
    // Create a clear button
    Button b = new Button("Clear");
    // Define, instantiate, and register a listener to handle button
    // presses
    b.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {  // clear the scribble
        Graphics g = getGraphics();
        g.setColor(getBackground());
        g.fillRect(0, 0, getSize().width, getSize().height);
      }
    });

    // And add the button to the applet
    this.add(b);
  }
  protected int lastx, lasty;  // Coordinates of last mouse click
}


$tigger javac StandaloneScribble.java

$tigger java StandaloneScribble
0
 

Author Comment

by:karana
ID: 12066315
i got it sir ,

 i dont know how it worked , but doing trial and error ,


 i added this line

 import java.lang. * ;

0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12319474
PAQed, with points refunded (50)

Computer101
E-E Admin
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 196
Java JRE greater than 1.6 5 63
rhino JavaScript import, load 25 85
jsp insert to database example 2 26
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question