main method netbeans

238
07 февраля 2018, 12:33

Есть JFrame в котором выполняются действия по нажатию JButton. Пишу код в строке обработчика события , но сам проект не запускается, т.к. не объявлен main method. Объявив в начале

public static void main(String[] args){

Выбивает кучу ошибок и не компилирует программу. Вот как я пытаюсь решить задачу:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
try { 
    ProcessBuilder pb = new ProcessBuilder("/home/alex/Desktop/BASH/script");
        System.out.println("Run discovering");
        Process process = pb.start();
                int errCode = process.waitFor();
        System.out.println("Discover was executed, with any errors? " + (errCode == 0 ? "No" : "Yes"));
        //System.out.println( output(process.getInputStream()); 
    } catch (IOException e)   {
            System.out.println("error");
        }
        }   
try {
        FileReader fr = new FileReader("/home/alex/Desktop/BASH/FiltredInterface.txt");
        BufferedReader br = new BufferedReader(fr);
        String text="";
        String str;
        while ((str = br.readLine()) != null) {
            System.out.println(str + "\n");
            text+=str + "\n";
}
        jTextPane1.setText(text);
        br.close(); 
    } catch (IOException e) {
        System.out.println("File not found");
    }

Куда правильнее объявить метод? Я пытался объявить метод вот так:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        public static void main(String[] args){
try { 
    ProcessBuilder pb = new ProcessBuilder("/home/alex/Desktop/BASH/script");

вот полный класс:

package com.lldpdiscover.alex;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class NewJFrame1 extends javax.swing.JFrame {
    /**
     * Creates new form NewJFrame1
     */
    public NewJFrame1() {
        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">                          
    private void initComponents() {
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane2 = new javax.swing.JTextPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextPane3 = new javax.swing.JTextPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextPane4 = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jButton1.setForeground(new java.awt.Color(198, 73, 73));
        jButton1.setText("Discover");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jScrollPane1.setViewportView(jTextPane1);
        jScrollPane2.setViewportView(jTextPane2);
        jScrollPane3.setViewportView(jTextPane3);
        jScrollPane4.setViewportView(jTextPane4);
        jLabel1.setText("Which Interfaces you have");
        jLabel2.setText("Which OS you have");
        jLabel3.setText("Which IP you have");
        jLabel4.setText("Which  Chassis");
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton1)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
                            .addComponent(jScrollPane3)
                            .addComponent(jScrollPane4)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(179, 179, 179)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(192, 192, 192)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(204, 204, 204)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(202, 202, 202)
                        .addComponent(jLabel4)))
                .addContainerGap(481, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jButton1)
                .addGap(21, 21, 21)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addGap(3, 3, 3)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addGap(9, 9, 9)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35))
        );
        pack();
    }// </editor-fold>                        
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

try {
        FileReader fr = new FileReader("/home/alex/Desktop/BASH/FiltredInterface.txt");
        BufferedReader br = new BufferedReader(fr);
        String text="";
        String str;
        while ((str = br.readLine()) != null) {
            System.out.println(str + "\n");
            text+=str + "\n";
}
        jTextPane1.setText(text);
        br.close(); 
    } catch (IOException e) {
        System.out.println("File not found");
    }
try { 
        FileReader fr2 = new FileReader("/home/alex/Desktop/BASH/FiltredSystemNames.txt");
        BufferedReader br2 = new BufferedReader(fr2);
        String text="";
        String str;
        while ((str = br2.readLine()) != null) {
            System.out.println(str + "\n");
            text+=str + "\n";
}
        jTextPane2.setText(text);
        br2.close(); 
    } catch (IOException e) {
        System.out.println("File not found");
    }
try { 
    FileReader fr3 = new FileReader("/home/alex/Desktop/BASH/FiltredIP.txt");
        BufferedReader br3 = new BufferedReader(fr3);
        String text="";
        String str;
        while ((str = br3.readLine()) != null) {
            System.out.println(str + "\n");
            text+=str + "\n";
}
        jTextPane3.setText(text);
        br3.close(); 
    } catch (IOException e) {
        System.out.println("File not found");
    }
try {
    FileReader fr4 = new FileReader("/home/alex/Desktop/BASH/FiltredChassis.txt");
        BufferedReader br4 = new BufferedReader(fr4);
        String text="";
        String str;
        while ((str = br4.readLine()) != null) {
            System.out.println(str + "\n");
            text+=str + "\n";
}
        jTextPane4.setText(text);
        br4.close(); 
    } catch (IOException e) {
        System.out.println("File not found");
}

    }                                        
    /**
     * @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(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewJFrame1.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 NewJFrame1().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTextPane jTextPane2;
    private javax.swing.JTextPane jTextPane3;
    private javax.swing.JTextPane jTextPane4;
    // End of variables declaration                   
}
READ ALSO
сделать только один активный accordion jquery ui

сделать только один активный accordion jquery ui

Сделал аккордеон с помощью jQuery UI, непонятно почему, но не могу добиться, чтобы при открытии одного аккордеона остальные сворачивалисьНа странице...

220
Вылазит при добавлении .prepend()

Вылазит при добавлении .prepend()

Собственно попытался сам написать адаптивное меню, программирование знаю не очень хорошо

231