![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2004
Posts: 3
Rep Power: 0
![]() |
import java.applet.*;
import java.awt.*; public class Ballbewegung1 extends Applet implements Runnable { // Initialisierung der Variablen int x_pos = 10; // x - Position des Balles int y_pos = 100; // y - Position des Balles int radius = 20; // Radius des Balles public void init() { setBackground (Color.blue); } public void start () { // Schaffen eines neuen Threads, in dem das Spiel läuft Thread th = new Thread (this); // Starten des Threads th.start (); } public void stop() { } public void destroy() { } public void run () { // Erniedrigen der ThreadPriority um zeichnen zu erleichtern Thread.currentThread().setPriority(Thread.MIN_PRIORITY); // Solange true ist läuft der Thread weiter while (true) { // Verändern der x- Koordinate x_pos ++; // Neuzeichnen des Applets repaint(); try { // Stoppen des Threads für in Klammern angegebene Millisekunden Thread.sleep (20); } catch (InterruptedException ex) { // do nothing } // Zurücksetzen der ThreadPriority auf Maximalwert Thread.currentThread().setPriority(Thread.MAX_PRIORITY); } } public void paint (Graphics g) { g.setColor (Color.red); g.fillOval (x_pos - radius, y_pos - radius, 2 * radius, 2 * radius); } this give this message when i run it:Exception in thread "main" java.lang.NoSuchMethodError: main |
|
|
|
|
|
#2 |
|
PFO Founder
![]() ![]() |
i recieve that error when i run the code in console but you have created an applet here not an application. so you will need to run the appletviewer to see the results. i personally havent tryed it but i think that is what the problem is. you could try adding the .class to an help webpage and then opening he html page in your browser and see if it shows it
and see what happens. i could be wrong but give it a try and see what happens. ![]() ok i was correct. cause i got it to work fine for me. here is what i did. i created an html doc with the following code in it. and then opened it up <html> <head><title>java applet test</title></head> <body> <APPLET CODE="Ballbewegung1.class" WIDTH="100" HEIGHT="100"> </APPLET> </body> </html> this will make your applet work perfectly good luck ![]()
__________________
BIG K aka Kyle Programming Forums Kyle K Online Please do not PM or email me programming questions. Post them in the forums instead. |
|
|
|
|
|
#3 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Yup. Appletviewer should do the trick.
![]()
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Aug 2004
Posts: 3
Rep Power: 0
![]() |
Thanx boss.....u r great
) |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2004
Posts: 3
Rep Power: 0
![]() |
I have got another problem....
import java.net.*;
import java.io.*;
public class SourceViewer {
public static void main (String args[]){
if (args.length>0){
try{
URL u=new URL(args[0]);
URLConnection uc = u.openConnection();
InputStream in = uc.getInputStream();
in = new BufferedInputStream(in);
Reader r = new InputStreamReader(in);
int c;
while((c = r.read()) != -1){
System.out.print((char) c);
}
}
catch (MalformedURLException e) {
System.err.println(args[0] + "is not a parseable URL");
}
catch (IOException e) {
System.err.println(e);
}
}
}when i run this code in Fedora 1 i get a "UnKnownHost" error......can u help me in fixing it????? |
|
|
|
|
|
#6 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
I'm not positive, but try changing
URL u=new URL(args[0]); with URL u=new URL(args[1]); I would think that args[0] would refer to the name of your program.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|