클래스를 다시 추가 한 후에 클래스를 다시 칠하는 데 문제가 있습니다.다른 클래스의 JPanel을 다시 작성하십시오.
public class Window extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private MediaHandler myMediaHandler = new MediaHandler(this);
class MenuActionListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String buttonText = e.getActionCommand();
switch(buttonText) {
case "Add Movie":
AddMovieWindow addMovieGUI = new AddMovieWindow(myMediaHandler);
addMovieGUI.setVisible(true);
break;
case "Add TV-Show":
AddTVShowWindow addTVShowGUI = new AddTVShowWindow(myMediaHandler);
addTVShowGUI.setVisible(true);
break;
}
}
}
public Window() {
// myMediaHandler.addMovie("Nineteen Eighty-Four", 113.00, 1984, "Michael Radford", "mediaPath", "https://dl.dropboxusercontent.com/u/16670644/Projekt/1984.png", "HD", false, "Eng", "George Orwell (novel)");
addComponents();
configurFrame();
addMenu();
validate();
repaint();
}
private void addMenu() {
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("Menu");
bar.add(menu);
JMenuItem item = new JMenuItem("Add Movie");
item.addActionListener(new MenuActionListener());
menu.add(item);
item = new JMenuItem("Add TV-Show");
item.addActionListener(new MenuActionListener());
menu.add(item);
this.setJMenuBar(bar);
}
private void configurFrame() {
this.setSize(1205, 850);
this.setTitle("Video Library");
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setIconImage(new ImageIcon("E:\\Dropbox\\Dropbox\\Programmering\\Java\\Projekt IV 1\\icon.png").getImage());
try {
java.net.URL where = new URL("https://dl.dropboxusercontent.com/u/16670644/Projekt/BackGround.png");
ImageIcon image = new ImageIcon(where);
JLabel imageLabel = new JLabel(image);
this.add(imageLabel);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("Error loading Background that makes the background image");
e.printStackTrace();
}
}
private void addComponents() {
JPanel shelfs = buildShelfs();
this.add(shelfs);
}
private JPanel buildShelfs() {
JPanel mediaPanel = new JPanel();
int nrOfMedias = myMediaHandler.mediaList.size();
mediaPanel.setOpaque(false);
mediaPanel.setLayout(new GridLayout(3,6,22,30));
mediaPanel.setBounds(90, 25, 1020, 745);
java.net.URL where;
for(int i = 0; i < nrOfMedias; i++) {
String temp = myMediaHandler.mediaList.get(i).getImagePath();
try {
where = new URL(temp);
ImageIcon image = new ImageIcon(where);
JLabel imageLabel = new JLabel(image);
mediaPanel.add(imageLabel);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("Error loading user media picture");
e.printStackTrace();
}
}
java.net.URL where1;
try {
for(int i = nrOfMedias; i < 18; i++) {
where1 = new URL("https://dl.dropboxusercontent.com/u/16670644/Projekt/TempPic.png");
ImageIcon image1 = new ImageIcon(where1);
JLabel imageLabel1 = new JLabel(image1);
mediaPanel.add(imageLabel1);
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("Error loading TempPic that shows allowed media spots");
e.printStackTrace();
}
return mediaPanel;
}
public static void main(String[] arg) {
Window mainWindowGUI = new Window();
mainWindowGUI.setVisible(true);
}
}
내가 지금하려는 것은 rapaint 함수를 호출하는 다른 클래스의 것입니다.
public class MediaHandler {
ArrayList<Media> mediaList;
private Window myWindow;
public MediaHandler(Window window) {
this.mediaList = new ArrayList<Media>();
myWindow = window;
}
public void addMovie(String title, Double playTime, int year,
String directory, String mediaPath, String imagePath, String quality,
boolean subtitles, String language, String writer) {
mediaList.add(new Movie(title, playTime, year, false, directory, mediaPath, imagePath, rating.unrated, quality, subtitles, language, writer));
myWindow.getContentPane().invalidate();
myWindow.invalidate();
}
}
불명확 한 것이 있으면 알려주세요! 나는 며칠 동안이 문제에 갇혀있다.
문제 설명이 명확하지 않습니다. 자세한 내용을 설명하십시오. 어디서 붙어 있었습니까? – Braj
'MediaHandler'가'repaint'를 호출하지 않거나 뭔가 빠졌습니다. – csmckelvey
buildShelfs 함수는 동영상 포스터 이미지를 추가합니다. 새 동영상을 추가하면 buildShelf 영역을 이미지를 표시 할 수 있도록 다시 그려야합니다. [link] (https://dl.dropboxusercontent.com/u/16670644/programImg.PNG)이 이미지는 프로그램의 실행을 보여줍니다. 이제 배열에 새 객체를 추가하면이 객체도 표시되기를 원합니다. 그건 본질적으로 제 문제입니다. buildShelfs 함수의 첫 번째 반복은 arrayList에서 URL을 가져오고 실제로 새 동영상을 추가 할 수 있음을 확인했습니다. – seb