좋아,이 일이 왜 발생하는지 몰라도 닫기 버튼을 누르면 joptionpane이 닫히지 않습니다. 그것은 계속해서 다시 터지기 때문에 그것을 닫으려면 여러 번 클릭해야합니다. 배치하는 잘못된 코드 이전 : JOptionPane이 닫히지 않습니다
다음은 코드Point p;
p = onScreenLocation(0.134,0.019, eastlake);
btn.setBounds(p.x,p.y,128,96);
btn.setContentAreaFilled(false);
btn.setBorderPainted(false);
add(btn);
btn.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
Object[] options = {"View Info","View Place","Close"};
Object[] choice ={"Close"};
int response = JOptionPane.showOptionDialog(null,"Apartment Area","Message",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,ResidentImage,options,"Close");
if(response == 0){
JOptionPane.showOptionDialog(null, "Apartment Eastlake \n" +
"provides students with conducive room and reasonable prices ", "Message", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,ResidentImage,choice,"Close");
}
else if(response == 1){
JFrame ImageBox = new JFrame();
ImageBox.setSize(300,400);
ImageBox.add(new JLabel(ResidentImageView,SwingConstants.CENTER));
ImageBox.setVisible(true);
}
else{
}
}
});
전체 코드 편집
package environment;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
public class Map extends JPanel{
String time = null;
serializedObject[] humans2 = null;
serializedDatas input = new serializedDatas();
Image eastlake,otherImage, buddyImage, clientImage, EventImage;
String[] buddyList;
String clientName;
JFrame frame;
ClassLoader cl = this.getClass().getClassLoader();
ImageIcon TransparentImage = new ImageIcon(cl.getResource("image1/bnt1.png"));
ImageIcon TescoImageView = new ImageIcon(cl.getResource("image1/tesco.jpg"));
ImageIcon TescoImage = new ImageIcon(cl.getResource("image1/Tesco.png"));
JButton btn = new JButton(TransparentImage);
public Map(Image map, Image agent, Image buddy, Image other, String clientName){
eastlake = map;
clientImage = agent;
otherImage = other;
buddyImage = buddy;
this.clientName = clientName;
}
protected void paintComponent(Graphics g)
{
super.paintComponents(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(eastlake,0,0,null);
this.setPreferredSize(new Dimension(2624,1696));
Font font = new Font("Helvetica", Font.BOLD, 12);
g2d.setFont(font);
g2d.setColor(Color.red);
if(time != null)
g2d.drawString(time, 10, 10);
Point p;
p = onScreenLocation(0.134,0.019, eastlake);
btn.setBounds(p.x,p.y,128,96);
btn.setContentAreaFilled(false);
btn.setBorderPainted(false);
add(btn);
btn.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent me){
Object[] options = {"View Info","View Place","Close"};
Object[] choice ={"Close"};
int response = JOptionPane.showOptionDialog(null,"Apartment Area","Message",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE,ResidentImage,options,"Close");
if(response == 0){
JOptionPane.showOptionDialog(null, "Apartment Eastlake \n" +
"provides students with conducive room and reasonable prices ", "Message", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,ResidentImage,choice,"Close");
}
else if(response == 1){
JFrame ImageBox = new JFrame();
ImageBox.setSize(300,400);
ImageBox.add(new JLabel(ResidentImageView,SwingConstants.CENTER));
ImageBox.setVisible(true);
}
else{
}
}
});
}
public void setTime(String time2) {
// TODO Auto-generated method stub
this.time = time2;
}
public void setBuddyList(String[] buddyList2) {
// TODO Auto-generated method stub
this.buddyList = buddyList2;
}
protected Point onScreenLocation(double x, double y, Image img)
{
return new Point((int)(img.getWidth(null)*x),(int)(img.getHeight(null)*y));
}
}
의 스냅 샷.
처음에는 ** 문제를 해결하는 ** 최소 ** 코드 샘플까지 문제를 단순화하십시오. 위의 코드 중 90 %가 현재 당면한 문제와 전혀 관련이 없다고 말했습니다. (http : //sscce.org/ ...를보십시오) –