Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Java - 2 Domande sul Java
Forum - Java - 2 Domande sul Java

Avatar
Luk3 (Ex-Member)
Guru


Messaggi: 615
Iscritto: 16/08/2008

Segnala al moderatore
Postato alle 19:36
Martedì, 30/09/2008
1) In Visual Studio, se su un form trascino un button, mi basta cliccarci sopra due volte per accedere all'evento button e scrivere il codice da eseguire... Ma su netbeans?
Ho visto che se carico un programma "Sample" posso clikare una volta sul button e andare al codice, ma se creo una nuova java desktop application non succede!

2) Quando avvio il mio programmino in formato *.jar
mi dice "Could not find the main class. Program will exit."
E si chiude... Perchè? Come risolvo?


Grazie ;)

PM Quote
Avatar
Luk3 (Ex-Member)
Guru


Messaggi: 615
Iscritto: 16/08/2008

Segnala al moderatore
Postato alle 20:59
Martedì, 30/09/2008
Domanda 1 risolta:

Allora, per chiunque si trovasse nella mia situazione...

- Click destro sul controllo (jButton1 per esempio).
- events
- Action
- actionPerformed

:k:

PM Quote
Avatar
VaLeRiO (Ex-Member)
Pro


Messaggi: 114
Iscritto: 28/06/2008

Segnala al moderatore
Postato alle 16:57
Mercoledì, 01/10/2008
Perchè nella creazione del JAR non specifichi il punto di entrata dell'applicazione, cioè il main.

Controlla bene che venga specificata la classe contenente il main.

PM Quote
Avatar
Luk3 (Ex-Member)
Guru


Messaggi: 615
Iscritto: 16/08/2008

Segnala al moderatore
Postato alle 17:02
Mercoledì, 01/10/2008
Questo è il codice, dov'è l'errore -_- ?

Codice sorgente - presumibilmente Java

  1. /*
  2.  * ImpegniView.java
  3.  */
  4.  
  5. package impegni;
  6.  
  7. import org.jdesktop.application.Action;
  8. import org.jdesktop.application.ResourceMap;
  9. import org.jdesktop.application.SingleFrameApplication;
  10. import org.jdesktop.application.FrameView;
  11. import org.jdesktop.application.TaskMonitor;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import javax.swing.Timer;
  15. import javax.swing.Icon;
  16. import javax.swing.JDialog;
  17. import javax.swing.JFrame;
  18.  
  19. /**
  20.  * The application's main frame.
  21.  */
  22. public class ImpegniView extends FrameView {
  23.  
  24.     public ImpegniView(SingleFrameApplication app) {
  25.         super(app);
  26.  
  27.         initComponents();
  28.  
  29.         // status bar initialization - message timeout, idle icon and busy animation, etc
  30.         ResourceMap resourceMap = getResourceMap();
  31.         int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
  32.         messageTimer = new Timer(messageTimeout, new ActionListener() {
  33.             public void actionPerformed(ActionEvent e) {
  34.                 statusMessageLabel.setText("");
  35.             }
  36.         });
  37.         messageTimer.setRepeats(false);
  38.         int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
  39.         for (int i = 0; i < busyIcons.length; i++) {
  40.             busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
  41.         }
  42.         busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
  43.             public void actionPerformed(ActionEvent e) {
  44.                 busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
  45.                 statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
  46.             }
  47.         });
  48.         idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
  49.         statusAnimationLabel.setIcon(idleIcon);
  50.         progressBar.setVisible(false);
  51.  
  52.         // connecting action tasks to status bar via TaskMonitor
  53.         TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
  54.         taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
  55.             public void propertyChange(java.beans.PropertyChangeEvent evt) {
  56.                 String propertyName = evt.getPropertyName();
  57.                 if ("started".equals(propertyName)) {
  58.                     if (!busyIconTimer.isRunning()) {
  59.                         statusAnimationLabel.setIcon(busyIcons[0]);
  60.                         busyIconIndex = 0;
  61.                         busyIconTimer.start();
  62.                     }
  63.                     progressBar.setVisible(true);
  64.                     progressBar.setIndeterminate(true);
  65.                 } else if ("done".equals(propertyName)) {
  66.                     busyIconTimer.stop();
  67.                     statusAnimationLabel.setIcon(idleIcon);
  68.                     progressBar.setVisible(false);
  69.                     progressBar.setValue(0);
  70.                 } else if ("message".equals(propertyName)) {
  71.                     String text = (String)(evt.getNewValue());
  72.                     statusMessageLabel.setText((text == null) ? "" : text);
  73.                     messageTimer.restart();
  74.                 } else if ("progress".equals(propertyName)) {
  75.                     int value = (Integer)(evt.getNewValue());
  76.                     progressBar.setVisible(true);
  77.                     progressBar.setIndeterminate(false);
  78.                     progressBar.setValue(value);
  79.                 }
  80.             }
  81.         });
  82.     }
  83.  
  84.     @Action
  85.     public void showAboutBox() {
  86.         if (aboutBox == null) {
  87.             JFrame mainFrame = ImpegniApp.getApplication().getMainFrame();
  88.             aboutBox = new ImpegniAboutBox(mainFrame);
  89.             aboutBox.setLocationRelativeTo(mainFrame);
  90.         }
  91.         ImpegniApp.getApplication().show(aboutBox);
  92.     }
  93.  
  94.     /** This method is called from within the constructor to
  95.      * initialize the form.
  96.      * WARNING: Do NOT modify this code. The content of this method is
  97.      * always regenerated by the Form Editor.
  98.      */
  99.     @SuppressWarnings("unchecked")
  100.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  101.     private void initComponents() {
  102.  
  103.         mainPanel = new javax.swing.JPanel();
  104.         list1 = new java.awt.List();
  105.         jButton1 = new javax.swing.JButton();
  106.         jButton2 = new javax.swing.JButton();
  107.         jButton3 = new javax.swing.JButton();
  108.         jTextField1 = new javax.swing.JTextField();
  109.         menuBar = new javax.swing.JMenuBar();
  110.         javax.swing.JMenu fileMenu = new javax.swing.JMenu();
  111.         javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
  112.         javax.swing.JMenu helpMenu = new javax.swing.JMenu();
  113.         javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
  114.         statusPanel = new javax.swing.JPanel();
  115.         javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
  116.         statusMessageLabel = new javax.swing.JLabel();
  117.         statusAnimationLabel = new javax.swing.JLabel();
  118.         jLabel1 = new javax.swing.JLabel();
  119.         progressBar = new javax.swing.JProgressBar();
  120.  
  121.         mainPanel.setName("mainPanel"); // NOI18N
  122.  
  123.         list1.setName("list1"); // NOI18N
  124.  
  125.         org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(impegni.ImpegniApp.class).getContext().getResourceMap(ImpegniView.class);
  126.         jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
  127.         jButton1.setName("jButton1"); // NOI18N
  128.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  129.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  130.                 jButton1ActionPerformed(evt);
  131.             }
  132.         });
  133.  
  134.         jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
  135.         jButton2.setName("jButton2"); // NOI18N
  136.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  137.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  138.                 jButton2ActionPerformed(evt);
  139.             }
  140.         });
  141.  
  142.         jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
  143.         jButton3.setName("jButton3"); // NOI18N
  144.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  145.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  146.                 jButton3ActionPerformed(evt);
  147.             }
  148.         });
  149.  
  150.         jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
  151.         jTextField1.setName("jTextField1"); // NOI18N
  152.  
  153.         javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
  154.         mainPanel.setLayout(mainPanelLayout);
  155.         mainPanelLayout.setHorizontalGroup(
  156.             mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  157.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
  158.                 .addContainerGap()
  159.                 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  160.                     .addGroup(mainPanelLayout.createSequentialGroup()
  161.                         .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
  162.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  163.                         .addComponent(jButton1))
  164.                     .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  165.                         .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  166.                         .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)))
  167.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  168.                 .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
  169.                 .addGap(20, 20, 20))
  170.         );
  171.         mainPanelLayout.setVerticalGroup(
  172.             mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  173.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
  174.                 .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  175.                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, mainPanelLayout.createSequentialGroup()
  176.                         .addContainerGap()
  177.                         .addComponent(list1, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))
  178.                     .addGroup(mainPanelLayout.createSequentialGroup()
  179.                         .addGap(19, 19, 19)
  180.                         .addComponent(jButton2)
  181.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  182.                         .addComponent(jButton3)
  183.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 131, Short.MAX_VALUE)
  184.                         .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  185.                             .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  186.                             .addComponent(jButton1))))
  187.                 .addContainerGap())
  188.         );
  189.  
  190.         menuBar.setName("menuBar"); // NOI18N
  191.  
  192.         fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
  193.         fileMenu.setName("fileMenu"); // NOI18N
  194.  
  195.         javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(impegni.ImpegniApp.class).getContext().getActionMap(ImpegniView.class, this);
  196.         exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
  197.         exitMenuItem.setIcon(resourceMap.getIcon("exitMenuItem.icon")); // NOI18N
  198.         exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
  199.         exitMenuItem.setName("exitMenuItem"); // NOI18N
  200.         fileMenu.add(exitMenuItem);
  201.  
  202.         menuBar.add(fileMenu);
  203.  
  204.         helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
  205.         helpMenu.setName("helpMenu"); // NOI18N
  206.  
  207.         aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
  208.         aboutMenuItem.setIcon(resourceMap.getIcon("aboutMenuItem.icon")); // NOI18N
  209.         aboutMenuItem.setName("aboutMenuItem"); // NOI18N
  210.         helpMenu.add(aboutMenuItem);
  211.  
  212.         menuBar.add(helpMenu);
  213.  
  214.         statusPanel.setName("statusPanel"); // NOI18N
  215.  
  216.         statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
  217.  
  218.         statusMessageLabel.setName("statusMessageLabel"); // NOI18N
  219.  
  220.         statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
  221.         statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
  222.  
  223.         jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
  224.         jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
  225.         jLabel1.setName("jLabel1"); // NOI18N
  226.  
  227.         progressBar.setName("progressBar"); // NOI18N
  228.  
  229.         javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
  230.         statusPanel.setLayout(statusPanelLayout);
  231.         statusPanelLayout.setHorizontalGroup(
  232.             statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  233.             .addGroup(statusPanelLayout.createSequentialGroup()
  234.                 .addContainerGap()
  235.                 .addComponent(statusMessageLabel)
  236.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
  237.                 .addComponent(jLabel1)
  238.                 .addGap(83, 83, 83)
  239.                 .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  240.                     .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
  241.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
  242.                         .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  243.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  244.                         .addComponent(statusAnimationLabel)
  245.                         .addContainerGap())))
  246.         );
  247.         statusPanelLayout.setVerticalGroup(
  248.             statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  249.             .addGroup(statusPanelLayout.createSequentialGroup()
  250.                 .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
  251.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
  252.                 .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  253.                     .addComponent(statusMessageLabel)
  254.                     .addComponent(statusAnimationLabel)
  255.                     .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  256.                 .addGap(3, 3, 3))
  257.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, statusPanelLayout.createSequentialGroup()
  258.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  259.                 .addComponent(jLabel1)
  260.                 .addContainerGap())
  261.         );
  262.  
  263.         setComponent(mainPanel);
  264.         setMenuBar(menuBar);
  265.         setStatusBar(statusPanel);
  266.     }// </editor-fold>                        
  267.  
  268. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  269. list1.add(jTextField1.getText());
  270. jTextField1.setText("");
  271. }                                        
  272.  
  273. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  274. list1.remove(list1.getSelectedIndex());
  275. }                                        
  276.  
  277. private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  278. list1.clear();
  279. }                                        
  280.  
  281.     // Variables declaration - do not modify                    
  282.     private javax.swing.JButton jButton1;
  283.     private javax.swing.JButton jButton2;
  284.     private javax.swing.JButton jButton3;
  285.     private javax.swing.JLabel jLabel1;
  286.     private javax.swing.JTextField jTextField1;
  287.     private java.awt.List list1;
  288.     private javax.swing.JPanel mainPanel;
  289.     private javax.swing.JMenuBar menuBar;
  290.     private javax.swing.JProgressBar progressBar;
  291.     private javax.swing.JLabel statusAnimationLabel;
  292.     private javax.swing.JLabel statusMessageLabel;
  293.     private javax.swing.JPanel statusPanel;
  294.     // End of variables declaration                  
  295.  
  296.     private final Timer messageTimer;
  297.     private final Timer busyIconTimer;
  298.     private final Icon idleIcon;
  299.     private final Icon[] busyIcons = new Icon[15];
  300.     private int busyIconIndex = 0;
  301.  
  302.     private JDialog aboutBox;
  303. }


PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 17:05
Mercoledì, 01/10/2008
L'errore è che non c'è il main. Se non c'è il punto d'ingresso l'applicazione come fa a partire?


Il mio blog: https://piero.dev
PM Quote
Avatar
Luk3 (Ex-Member)
Guru


Messaggi: 615
Iscritto: 16/08/2008

Segnala al moderatore
Postato alle 17:21
Mercoledì, 01/10/2008
Scusate per la mia ignoranza, io programmo in C# :rotfl:

Come risolvo?

PM Quote