|
@@ -0,0 +1,134 @@
|
|
|
+/*
|
|
|
+ * 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 javaapp1;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author Анастасия
|
|
|
+ */
|
|
|
+public class Frame1 extends javax.swing.JFrame {
|
|
|
+
|
|
|
+ boolean btext = true; // добавим логическую переменную
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates new form Frame1
|
|
|
+ */
|
|
|
+ public Frame1() {
|
|
|
+ initComponents();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 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.
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
|
+ private void initComponents() {
|
|
|
+
|
|
|
+ jButton1 = new javax.swing.JButton();
|
|
|
+ jButton2 = new javax.swing.JButton();
|
|
|
+ jLabel1 = new javax.swing.JLabel();
|
|
|
+
|
|
|
+ setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
|
|
+
|
|
|
+ jButton1.setText("Вывод текста");
|
|
|
+ jButton1.addActionListener(new java.awt.event.ActionListener() {
|
|
|
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
+ jButton1ActionPerformed(evt);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ jButton2.setText("Открытие окна");
|
|
|
+ jButton2.addActionListener(new java.awt.event.ActionListener() {
|
|
|
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
|
+ jButton2ActionPerformed(evt);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ jLabel1.setText(" ");
|
|
|
+
|
|
|
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
|
|
+ getContentPane().setLayout(layout);
|
|
|
+ layout.setHorizontalGroup(
|
|
|
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
|
+ .addGroup(layout.createSequentialGroup()
|
|
|
+ .addGap(64, 64, 64)
|
|
|
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
|
|
+ .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
|
+ .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
|
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 102, Short.MAX_VALUE)
|
|
|
+ .addComponent(jLabel1)
|
|
|
+ .addGap(114, 114, 114))
|
|
|
+ );
|
|
|
+ layout.setVerticalGroup(
|
|
|
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
|
+ .addGroup(layout.createSequentialGroup()
|
|
|
+ .addGap(89, 89, 89)
|
|
|
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
|
+ .addComponent(jButton1)
|
|
|
+ .addComponent(jLabel1))
|
|
|
+ .addGap(54, 54, 54)
|
|
|
+ .addComponent(jButton2)
|
|
|
+ .addContainerGap(111, Short.MAX_VALUE))
|
|
|
+ );
|
|
|
+
|
|
|
+ pack();
|
|
|
+ }// </editor-fold>//GEN-END:initComponents
|
|
|
+
|
|
|
+ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
|
|
+ if(btext) {jLabel1.setText("Hello"); btext=false;} // если btext=true, записываем в наш JLabel запись, меняем btext на false
|
|
|
+ else{jLabel1.setText(""); btext=true;} // в ином случае, записываем пустой текст в JLabel, меняем btext на true
|
|
|
+
|
|
|
+ }//GEN-LAST:event_jButton1ActionPerformed
|
|
|
+
|
|
|
+ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
|
|
|
+ this.dispose(); // закрываем 1 окно
|
|
|
+ Frame2 fr = new Frame2(); // экземпляр класса 2 окна
|
|
|
+ fr.setVisible(true); // делаем его видимым
|
|
|
+ }//GEN-LAST:event_jButton2ActionPerformed
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param args the command line arguments
|
|
|
+ */
|
|
|
+ public static void main(String args[]) {
|
|
|
+ /* Set the Nimbus look and feel */
|
|
|
+ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
|
|
+ /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
|
|
+ * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
|
|
+ */
|
|
|
+ try {
|
|
|
+ for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
|
|
+ if ("Nimbus".equals(info.getName())) {
|
|
|
+ javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (ClassNotFoundException ex) {
|
|
|
+ java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
+ } catch (InstantiationException ex) {
|
|
|
+ java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
+ } catch (IllegalAccessException ex) {
|
|
|
+ java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
|
|
+ java.util.logging.Logger.getLogger(Frame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
|
|
+ }
|
|
|
+ //</editor-fold>
|
|
|
+
|
|
|
+ /* Create and display the form */
|
|
|
+ java.awt.EventQueue.invokeLater(new Runnable() {
|
|
|
+ public void run() {
|
|
|
+ new Frame1().setVisible(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // Variables declaration - do not modify//GEN-BEGIN:variables
|
|
|
+ private javax.swing.JButton jButton1;
|
|
|
+ private javax.swing.JButton jButton2;
|
|
|
+ private javax.swing.JLabel jLabel1;
|
|
|
+ // End of variables declaration//GEN-END:variables
|
|
|
+}
|