Zeilen 88,89,90,101,104: "non-static method cannot be referenced from a static context"
Ich finde nirgendwo (auch nicht in einem Buch oder diesem Forum) eine Lösung.
*Heul*
Ich finde nirgendwo (auch nicht in einem Buch oder diesem Forum) eine Lösung.
*Heul*
Code:
/*
* Main.java
*
* Created on 5. Mai 2007, 14:19
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package satstarter;
import java.applet.Applet;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import sun.net.ftp.*;
import java.net.*;
/**
*
* @author Daniel Ziltener
*/
public class Main extends Applet implements ActionListener
{
JLabel info;
JButton button;
JProgressBar progressbar;
/** Creates a new instance of Main */
public Main() {
}
//Initialisierung
public void init()
{
}
// Start-Void
public void start()
{
JPanel panel = new JPanel(new BorderLayout());
this.add(panel);
JLabel titel = new JLabel("Hiebe für Diebe!", SwingConstants.CENTER);
panel.add(titel);
info = new JLabel("", SwingConstants.CENTER);
panel.add(info);
button = new JButton("Spiel starten");
button.addActionListener(this);
panel.add(button, SwingConstants.CENTER);
progressbar = new JProgressBar();
progressbar.setVisible(false);
this.add(progressbar);
}
// Wenn der Button geklickt wird
public void actionPerformed(ActionEvent e)
{
button.setEnabled(false);
info.setText("Spiel wird gestartet.");
//Überprüfung, ob Datei existiert
File f = new File("c:\\lyrion\\sat\\sat.exe");
boolean exists = f.exists();
if(exists)
{
// Versuche, Spiel zu starten
try
{
Runtime r = Runtime.getRuntime();
Process p = r.exec("c:\\lyrion\\sat\\sat.exe");
p.exitValue();
}
catch (IOException g) { }
catch (IllegalThreadStateException g) { }
}
else
{
// Verbinde mit Server
ftpclass.FTPHandler ("lyrion.ch", "lyrionch", "tilsinow");
ftpclass.cd ("/public_ftp/games/");
ftpclass.binary();
String[] files = new String[] { "banners", "banners.ger", "bi_eng_01.gif", "bi_ger_01.gif", "clientconfig.cfg", "imagefile.dll", "mcgraphic.dll", "mcsound.dll", "mmgr.dll", "news", "news.ger", "renamer.exe", "s4_eng_01.gif", "s4_ger_01.gif", "sat.dat", "sat.exe", "satm.dat", "settings", "terminator.exe", "version"};
File folder = new File("c:\\lyrion\\sat");
folder.mkdirs();
File fil;
for(int t=0; t<files.length; t++)
{
fil = new File(folder + files[t]);
ftpclass.download (fil, files[t]);
}
ftpclass.quit();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
class ftpclass {
private FtpClient ftpc;
public void FTPHandler (String server, String username, String pass) throws IOException
{
ftpc = new FtpClient ();
ftpc.openServer (server);
ftpc.login (username, pass);
}
/**
* Wechselt das Verzeichnis
*/
public void cd (String to) throws IOException
{
ftpc.cd (to);
}
/**
* Wechselt in den binary - mode.
*/
public void binary() throws IOException
{
ftpc.binary();
}
/**
* Wechselt in den AscII - mode.
*/
public void ascII() throws IOException
{
ftpc.ascii();
}
/**
* Führt das noop - Commando aus.
*/
public void noop() throws IOException
{
ftpc.noop();
}
/**
* Lädt fil in eine neue Datei auf dem Server mit dem Namen name hoch.
*/
public void upload(File fil, String name) throws IOException
{
if (!fil.exists()){
throw new IllegalArgumentException ("The file doesn't exist");
}
OutputStream os = ftpc.put(name);
InputStream is = new FileInputStream (fil);
int len; byte[] buf = new byte[1024];
while ((len = is.read(buf)) >= 0){
os.write(buf, 0, len);
}
is.close();
os.close();
}
/**
* Lädt die Datei auf dem Server mit dem Namen name in fil down.
*/
public void download(File fil, String name) throws IOException
{
OutputStream os = new FileOutputStream (fil, false);
InputStream is = ftpc.get(name);
int len; byte[] buf = new byte[1024];
while ((len = is.read(buf)) >= 0){
os.write(buf, 0, len);
}
is.close();
os.close();
}
/**
* Beendet die Verbindung.
*/
public void quit() throws IOException
{
ftpc.closeServer();
}
}