问题描述
我想设置一个对话框模式化,结果运行起来还是非模式化,请求各路大神的解答
解决方案
解决方案二:
package抽签助手简易版;importjavax.swing.JDialog;importjavax.swing.JScrollPane;importjavax.swing.JTextArea;publicclassRecordFrameextendsJDialog{privateString[]record;publicJTextAreanote=newJTextArea();privateJScrollPanejsp=newJScrollPane(note);publicRecordFrame(Stringstr,inttimes,String[]digit){setTitle(str);record=newString[times];for(inti=0;i<times;i++){note.setText(note.getText()+"第"+(i+1)+"组:"+digit[i]+"n");}add(jsp);note.setEditable(false);setVisible(true);setSize(200,300);setLocation(620,300);setModal(true);}}
解决方案三:
package抽签助手简易版;importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Font;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.util.ArrayList;importjavax.swing.JButton;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.border.EmptyBorder;import抽签助手简易版.RecordFrame;import抽签助手简易版.MyThread;publicclassMainFrameextendsJFrameimplementsActionListener{/****/privatestaticfinallongserialVersionUID=-1696744269808441347L;privateJLabeltitle=newJLabel("计科系干部培训小组抽签助手",JLabel.CENTER);privateJButtonstart=newJButton("开始");privateJButtonend=newJButton("结束");privateJButtonreset=newJButton("重置");privateJButtonrecord=newJButton("记录");privateJButtonset=newJButton("设置");privateJLabeldigit=newJLabel("准备",JLabel.CENTER);privateJPanelpan1=newJPanel();privateJPanelpan2=newJPanel();privateJPanelpan3=newJPanel();privateinttimes=0;privateString[]str=newString[12];privateString[]progressValue={"01","02","03","04","05","06","07","08","09","10","11","12"};privateArrayList<String>p=newArrayList<String>();privateMyThreadt;publicMainFrame(Stringstr){setTitle(str);title.setFont(newFont("Serif",Font.PLAIN,20));digit.setOpaque(true);digit.setBackground(Color.BLACK);digit.setForeground(Color.RED);digit.setFont(newFont("Serif",Font.PLAIN,100));//pan3.setLayout(newGridLayout(2,1,6,6));pan1.setLayout(newBorderLayout(6,3));//pan3.add(record);//pan3.add(set);pan1.add(digit,BorderLayout.CENTER);pan2.setLayout(newGridLayout(1,3,6,6));end.setEnabled(false);reset.setEnabled(false);pan2.add(start);pan2.add(end);pan2.add(record);pan2.add(reset);add(title,BorderLayout.NORTH);add(pan1,BorderLayout.CENTER);add(pan2,BorderLayout.SOUTH);title.setBorder(newEmptyBorder(20,20,0,20));pan1.setBorder(newEmptyBorder(20,20,10,20));pan2.setBorder(newEmptyBorder(10,20,20,20));setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setResizable(false);setVisible(true);setLocation(550,260);setSize(400,350);for(inti=0;i<progressValue.length;i++){p.add(progressValue[i]);}t=newMyThread(digit,p);record.addActionListener(this);start.addActionListener(this);end.addActionListener(this);reset.addActionListener(this);}publicstaticvoidmain(String[]args){newMainFrame("抽签助手");}publicvoidactionPerformed(ActionEvente){//TODO自动生成的方法存根JButtonhandle=(JButton)e.getSource();if(handle==record){newRecordFrame("记录",times,str);}elseif(handle==start){t=newMyThread(digit,p);t.start();end.setEnabled(true);start.setEnabled(false);}elseif(handle==end){str[times]=digit.getText();times++;if(times<12){start.setEnabled(true);}else{digit.setText("完毕");}end.setEnabled(false);reset.setEnabled(true);p.remove(str[times-1]);t.stop();}elseif(handle==reset){t.stop();digit.setText("准备");p=newArrayList<String>();for(inti=0;i<progressValue.length;i++){p.add(progressValue[i]);}times=0;start.setEnabled(true);end.setEnabled(false);reset.setEnabled(false);}}}
解决方案四:
package抽签助手简易版;importjava.util.ArrayList;importjavax.swing.JLabel;publicclassMyThreadextendsThread{privateJLabeldigit;privateArrayList<String>p=newArrayList<String>();//privatebooleanchange=true;publicMyThread(JLabeldigit,ArrayList<String>p){this.digit=digit;this.p=p;for(inti=0;i<p.size();i++){//System.out.print(p.get(i)+"");}}@Overridepublicvoidrun(){for(inti=0;i<p.size();i++){try{Thread.sleep(10);}catch(Exceptione){}digit.setText(p.get(i));if(i==p.size()-1)i=-1;}}}