只是一个小小问题。 以下是我的方案2类方案拟定任务的一部分。 它侧重于继承和多个阶层。 我已回答了这个问题,但希望将课堂合并为主要职能,实际上建造一些东西,而不是仅仅提交最低课堂。
我的问题是下面的法典部分。 用户管理节目,向用户提供方言,询问他喜欢添加的内容(光盘或电影,两门课)。
What I would like though, is for the user to actually name the specific instance of the class while the program is running. So, the user will click Movie for example, be prompt to enter a name and then next line to use the constructor in the movie class to create a new instance class with the name the user entered? Is this possible? I tried using a simple string x = JOptionpane and then naming the class x also, but it didn t work. I m thinking there might be some method that will refer to the string? like contents.x maybe?
页: 1
import javax.swing.JOptionPane;
public class Main
{
public static void main (String args [])
{
Object[] options = {"Movie",
"CD",
"Cancel"};
int n = JOptionPane.showOptionDialog(null, "Would you like to add an item?","Product",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[2]);
switch(n)
{
case 0:
String moviet = JOptionPane.showInputDialog("Title:");
int movieID = Integer.parseInt(JOptionPane.showInputDialog("ID:"));
Movie moviett = new Movie(moviet, movieID);
}
}
}