저는 현재 모든 질문에 답하지 않으면 사용자에게 계속 진행할지 묻는 JOptionpane 확인 대화 상자가 나타나는 퀴즈 프로그램을 만들고 있습니다. 처음에는 모든 것이 잘 작동하고 있었고 프로그램 전체에서 paintComponent() 메서드를 사용하기로 결정했습니다. 이 구현 후,이 JOptionpane이 팝업되면 포함 된 Jpanel이 사라지고 (모든 질문을 표시 한 채로 표시됨) 배경 만 표시됩니다. 하루 종일 있었어. 문제가 발생한 코드는 다음과 같습니다.JOptionPane이 JPanel을 사라지게하는 것 같습니다.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package operator;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.swing.JOptionPane;
import static operator.Rules.examTimer;
import static operator.Welcome.image;
/**
*
* @author Hendy
*/
public class QuestionExams extends javax.swing.JPanel {
QuestionCall on = new QuestionCall();
int sBtn,nums = on.number();
/**
* Creates new form QuestionExams
*/
public QuestionExams() {
randomQuestion();
initComponents();
if (control == 0)
previousButton.setEnabled(false);
group.add(a);
group.add(b);
group.add(c);
group.add(d);
setSelected();
if (counter>=(maximum()-1) && control >= (maximum()-1))
{nextButton.setText("Finish");
finish.setVisible(false);}
if (counter== maximum() && control == maximum())
{
determinant();
}
}
public void determinant(){
if (checkAdd()<maximum())
{
{
sBtn = JOptionPane.showConfirmDialog(null, " Do you want to finish the exam?\n "
+ "Some questions are still unanswered",
"Proceed?",
JOptionPane.YES_NO_OPTION);
if (sBtn == JOptionPane.YES_OPTION)
{ wrongsAdd();
nextPage();
System.out.println("this shows the question key:"+wrongs.get(0));
System.out.println("this shows the question number:"+wrongNos.get(0));}
else
{
on.numberBack();
selection();
--control;
--key;
removeAll();
setLayout(new FlowLayout());
setLayout(new BorderLayout());
invalidate();
QuestionExams oan = new QuestionExams();
add(oan,BorderLayout.NORTH);
revalidate();
System.out.println("counter:"+counter +" and "+"control:" +control);
}
}
}
else
{
wrongsAdd();
nextPage();
}
}
public void paintComponent(Graphics g)
{
g.drawImage(image, 0, 0, null);
repaint();
}
@SuppressWarnings("unchecked")
private void initComponents() {
group = new javax.swing.ButtonGroup();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
examTiming = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
nameQ = new javax.swing.JTextArea();
jPanel4 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
a = new javax.swing.JRadioButton();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
b = new javax.swing.JRadioButton();
c = new javax.swing.JRadioButton();
d = new javax.swing.JRadioButton();
jScrollPane1 = new javax.swing.JScrollPane();
optA = new javax.swing.JTextArea();
jScrollPane3 = new javax.swing.JScrollPane();
optB = new javax.swing.JTextArea();
jScrollPane4 = new javax.swing.JScrollPane();
optC = new javax.swing.JTextArea();
jScrollPane5 = new javax.swing.JScrollPane();
optD = new javax.swing.JTextArea();
quitButton = new javax.swing.JButton();
previousButton = new javax.swing.JButton();
nextButton = new javax.swing.JButton();
finish = new javax.swing.JButton();
private void finishActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
removeAll();
setLayout(new FlowLayout());
setLayout(new BorderLayout());
invalidate();
AnswerCheck an = new AnswerCheck();
add(an, BorderLayout.NORTH);
revalidate();
wrongsAdd();
}
private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
{
selection();
if(control==counter){
{newAnswer();
{if ((QuestionCall.display6E(balance.get(key+1))+ "").equals(objective.get(control)))
scores=1;
else
scores =0;}
newScore();
if ("nothing".equals(value)){
check=0;
newCheck();
}
}
++counter;}
if (control<counter){
replaceAnswer();
{if ((QuestionCall.display6E(balance.get(key+1))+ "").equals(objective.get(control)))
scores=1;
else
scores =0;}
changeScore();
if ("nothing".equals(value)){
check=0;
validateCheck();
}
}
++control;
System.out.println(QuestionCall.display6E(balance.get(key+1)));
++key;
removeAll();
setLayout(new BorderLayout());
invalidate();
QuestionExams oan = new QuestionExams();
add(oan,BorderLayout.NORTH);
revalidate();
System.out.println(key);
System.out.println("counter:"+counter +" and "+"control:" +control+" position: "+position);
}
}
private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
on.numberBack();
selection();
--control;
--key;
removeAll();
setLayout(new FlowLayout());
setLayout(new BorderLayout());
invalidate();
QuestionExams oan = new QuestionExams();
add(oan,BorderLayout.NORTH);
revalidate();
System.out.println(QuestionCall.display6E(balance.get(key+1)));
System.out.println(key);
System.out.println("counter:"+counter +" and "+"control:" +control);
}
private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int select = JOptionPane.showConfirmDialog(null, "Do you really want to quit the test?",
"Quit?",
JOptionPane.YES_NO_OPTION);
if (select == JOptionPane.YES_OPTION)
// to
{
examTimer.stop();
on.clearFramework();
removeAll();
setLayout(new FlowLayout());
setLayout(new BorderLayout());
invalidate();
oktest an = new oktest();
add(an, BorderLayout.NORTH);
revalidate();}
}
}
private javax.swing.JRadioButton a;
private javax.swing.JRadioButton b;
private javax.swing.JRadioButton c;
private javax.swing.JRadioButton d;
public static javax.swing.JLabel examTiming;
private javax.swing.JButton finish;
private javax.swing.ButtonGroup group;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JPanel jPanel1;
public javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JTextArea nameQ;
private javax.swing.JButton nextButton;
private javax.swing.JTextArea optA;
private javax.swing.JTextArea optB;
private javax.swing.JTextArea optC;
private javax.swing.JTextArea optD;
private javax.swing.JButton previousButton;
private javax.swing.JButton quitButton;
}
대부분의 레이아웃 코드는 빠져 있습니다. 나는 또한 명확성을 위해 몇 가지 이미지를 포함시켰다.
먼저 마지막 질문 페이지입니다
다음 위로 내가 다음 버튼 (현재 표시되어 마감)
그리고 마지막으로,이 원작였다을 클릭하면 전에 일어나는 것이다 나는의 paintComponent() 메소드는, 불행하게도, 내가
나는 그것을하면 몰라 (난 그냥 .exe 파일이) 더 이상 이것에 대한 코드가없는 한 왜냐하면 Quit 버튼은 자체적으로 optionpane을 보여주고 완벽하게 표시되기 때문에 버그입니다.
-1 모든 Swing 구성 요소는 EDT (Event Dispatch Thread)에서 작성/수정해야합니다. – camickr
그래서 도움이 없다고 생각합니다 ......... * 한숨 * –