package miw2;
 
/**
 * Class contains question and butons YES and NO.
 * @author  Filip
 */
public class YNQuestion extends javax.swing.JFrame {
 
    /**
     * Value 'yes' or 'no' wchich is returned to prolog.
     */
    public static String sign = "";
 
    /**
     * Create Yes_or_No_Form with given question.
     * @param str question wchich answer is yes or no.
     */
    public YNQuestion(String[] str) {
        initComponents();
        sign = "";
        String question = "";
        for(String s: str){
            question+=s+"\n";
        }
        jTextArea1.setText(question);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(YNQuestion.DO_NOTHING_ON_CLOSE);
        this.setTitle("Please answer the question");
    }
 
    /**
     * Do loop until 'yes' or 'no' is pressed.
     * @return
     */
    public static String getValue(){
        try{
        while(sign.compareTo("")== 0){
            Thread.sleep(100);
        }
        } catch(Exception ex){
            ex.printStackTrace();
        }
        return sign;
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        jButton1.setText("NO");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
 
        jButton2.setText("YES");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
 
        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);
 
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(271, Short.MAX_VALUE)
                .add(jButton2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jButton1)
                .add(18, 18, 18))
            .add(layout.createSequentialGroup()
                .add(29, 29, 29)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                .add(26, 26, 26))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(21, 21, 21)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
                .add(38, 38, 38)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2))
                .addContainerGap())
        );
 
        pack();
    }// </editor-fold>                        
 
    /**
     * Action when button 'yes' is pressed.
     * @param evt event
     */
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        sign = "yes";
        this.dispose();
    }                                        
 
    /**
     * Action when button 'no' is pressed.
     * @param evt event.
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        sign = "no";
        this.dispose();
    }                                        
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new YNQuestion(new String[]{"one ","two"}).setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration                   
 
}
pl/miw/miw08_ruleruntimeg/ynquestion.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0