Solved

simple question

Posted on 2004-09-14
5
163 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now