问题描述
我正在使用内置的拖放式GUI构建器使用Netbeans构建GUI,我正努力获取jComboBox来获取数组列表,希望有人指出我做错了什么。我尝试的所有操作似乎都会导致错误,因此我在这里拔头发试图使其正常工作。
jComboBox1 = new javax.swing.JComboBox();
如果有人可以告诉我如何使用“可用的我的列表”填充comboBox,我将非常感谢
我已经在初始化的主要方法中包含了对象:
//Created a user object to represent a customer of the streaming service
User user;
//Initiliased video object
Video video ;
//Create new arraylist using AvailableVideos
List AvailableVideos = new ArrayList<>();
//Created CurrentPlaylist object to store a collection of video objects
List<Video> CurrentPlaylist= new ArrayList<>();
MyVideos myVideos = new MyVideos(user);
然后在我拥有的initComponents中
public GUI_App() {
initComponents();
//Call the AddVideos method to add available videos
Video.addVideos((ArrayList<Video>) AvailableVideos);
}
下面,我包含了我要调用的两个类
public class MyVideos {
private ArrayList<Video> items;
private int currentItemNumber;
private User user;
public MyVideos(User user) {
this.user = user;
this.items = new ArrayList<>();
this.currentItemNumber = 0;
}
public MyVideos() {
this.user = new User("Intro Account",1000);
this.items = new ArrayList<>();
freebieMedia();
this.currentItemNumber = 0;
}
private void freebieMedia(){
items.add(new Series("Game of Thrones",50,false));
items.add(new Series("Planet Earth",60,true));
items.add(new MusicVideo("Losing my religion",200,"REM"));
items.add(new Movie("The Last Jedi",9120,"Rian Johnson"));
}
public User getUser(){
return user;
}
public int getNumItems() {
return items.size();
}
public ArrayList<Video> getItems() {
return items;
}
public Video getMedia(int i) {
return items.get(i);
}
public void addMedia(Video m){
if(user.hasSufficientBalance(m)) {
items.add(m);
this.user.changeBalance(-m.getPrice());
}
System.out.println("added " + m.getTitle());
}
public String getScheduleAsstring(){
String rs = "";
for(Video m: items){
rs += m.toString() + "\n";
}
return rs;
}
public int getTotalDuration(){
int time = 0;
for(Video m: items){
time += m.getDuration();
}
return time;
}
public int getTotalCost(){
int cost = 0;
for(Video m: items){
cost += m.getPrice();
}
return cost;
}
@Override
public String toString() {
String str = "Number of Items:" + this.getNumItems() + "\t"
+ "Time: " + getTotalDuration()
+ getScheduleAsstring();
return str;
}
/* A method to add a media item without chargeing user's wallet */
public void addFreeMedia(Video m){
items.add(m);
} /* A method to remove a media item from the playlist */
public void removeMedia(int i) {
items.remove(i);
}
}
视频课程
public abstract class Video {
private int duration;
private String title;
public Video(String name,int minutes) {
this.title = name;
this.duration = minutes;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getDuration() {
return duration;
}
public void setDuration(int d) {
this.duration = d;
}
@Override
public String toString() {
DecimalFormat round = new DecimalFormat("0.00");
return this.getTitle()
+ ",Duration: " + this.getDuration() + "min," +
"Cost: £" + round.format(getPrice());
}
public abstract double getPrice();
/* Convenience method for Part 2 to allow Video objects can be added */
public static void addVideos(ArrayList<Video> v){
v.add(new Series("Game of Thrones",false));
v.add(new Series("Planet Earth",true));
v.add(new MusicVideo("Losing my religion",4,"REM"));
v.add(new Movie("The Last Jedi",152,"Rian Johnson"));
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)