-1
你可以在Java applet中的Applet/JApplet類之外有類嗎?您可以在Java applet中的Applet/JApplet類外部有類嗎?
你可以在Java applet中的Applet/JApplet類之外有類嗎?您可以在Java applet中的Applet/JApplet類外部有類嗎?
你的意思是你的applet項目中的java類在單獨的文件中? 答案是肯定的。
E.g. 兩類 MyApplet.java
和Person.java
這裏是MyApplet.java
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MyApplet extends JApplet implements ActionListener {
public void init() {
JButton button = new JButton("Click Me!");
button.addActionListener(this);
getContentPane().add(button);
}
@Override
public void actionPerformed(ActionEvent e) {
Person person = new Person();
person.setName("Jack");
person.setAge(18);
String title = "Greetings"; // Shown in title bar of dialog box.
String message = "Hello " + person.getName() + " from the Swing User Interface Library.";
JOptionPane.showMessageDialog(null, message, title,
JOptionPane.INFORMATION_MESSAGE);
}
}
這裏是Person.java類(在一個單獨的文件)
public class Person {
String name;
int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
是你可以,而且事實上你應該。您可以擁有一個jar文件,多個jar文件......就像任何Java應用程序一樣。 –