은 현재 작업이 끝난 이래로 프로젝트를 변경했습니다. 좀. 이미지가 여전히 변경되지 않습니다.처분되거나 보이지 않는 것으로 설정되는 자바
package icnon;
import javax.imageio.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FrameIconExample extends JFrame implements ActionListener {
JLabel j;
JPanel p, l, k;
JButton picOne, picTwo;
Container cPane;
public FrameIconExample() {
JButton picOne = new JButton("picOne");
JButton picTwo = new JButton("picTwo");
picOne.setName("picOne");
picTwo.setName("picTwo");
picOne.addActionListener(this);
picTwo.addActionListener(this);
p = new JPanel(new GridLayout(2, 1));
l = new JPanel(new FlowLayout());
k = new JPanel(new FlowLayout());
cPane = getContentPane();
j = new JLabel(new ImageIcon(
"../meet/src/images/beautiful-closeup-portrait-photography.jpg"));
l.add(j);
k.add(picOne);
k.add(picTwo);
p.add(l);
p.add(k);
add(p);
}
public static void main(String[] args) {
FrameIconExample frame = new FrameIconExample();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(new Dimension(300, 800));
frame.setTitle("Frame Icon Example");
// Display the form
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
JButton temp = (JButton) e.getSource();
String src = "../meet/src/images/Majken Kruse portrait - john.jpg";
//System.out.println(src + " " + temp.getName());
if (temp.getName().equalsIgnoreCase("picOne")) {
try {
l.hide();
try {
src = "../meet/src/images/beautiful-closeup-portrait-photography.jpg";
System.out.println(src + " " + temp.getName());
Icon img;
j = new JLabel(new ImageIcon(src));
l.add(j);
System.out.println("1");
} catch (Exception q) {
q.printStackTrace();
}
if (temp.getName().equalsIgnoreCase("picTwo")) {
src = "../icontest/images/Majken Kruse portrait - john.jpg";
System.out.println(src + " " + temp.getName());
Icon img;
j = new JLabel(new ImageIcon(src));
l.add(j);
System.out.println("2");
}
} catch (Exception x) {
x.printStackTrace();
}
}
}
}
잘못된 들여 쓰기. 메신저 꽤 확실한 방법 l.add (j); 이미지가 변하지 않는 이유입니다.
어떤 아이디어일까요?
스택 추적을 질문에 포함 할 수 있으면 도움이됩니다. – coobird
매우 큰 것 그러나 ok. 그 null 포인터 예외 – OVERTONE
오히려 새로운 질문을하십시오. 질문의 전체적인 의미를 편집하면 답변이 더 이상 적합하지 않습니다. 이전 버전으로 롤백하고 "예외 수정"상황을 다시 듣기 위해 제목을 변경하고 지금 다른 질문에서 작성한 내용을 묻는 것이 좋습니다. – Gnoupi