Example from www.tutorialspoint.com (java)

The example (below) gives an error (all other Itested from that site too, same error).
Link: Show Open File Dialog

Using the terminal.
I Pasted the code in TextEdit, saved it as SwingTester.java
Set cd in Terminal to point to the .java folder (checked with ls -l),
javac SwingTester

and get the error.

error: Class names, 'SwingTester', are only accepted if annotation processing is explicitly requested
1 error

idea(s) ?

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class SwingTester {
   public static void main(String[] args) {
      createWindow();
   }

   private static void createWindow() {    
      JFrame frame = new JFrame("Swing Tester");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      createUI(frame);
      frame.setSize(560, 200);      
      frame.setLocationRelativeTo(null);  
      frame.setVisible(true);
   }

   private static void createUI(final JFrame frame){  
      JPanel panel = new JPanel();
      LayoutManager layout = new FlowLayout();  
      panel.setLayout(layout);       

      JButton button = new JButton("Click Me!");
      final JLabel label = new JLabel();

      button.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            int option = fileChooser.showOpenDialog(frame);
            if(option == JFileChooser.APPROVE_OPTION){
               File file = fileChooser.getSelectedFile();
               label.setText("File Selected: " + file.getName());
            }else{
               label.setText("Open command canceled");
            }
         }
      });

      panel.add(button);
      panel.add(label);
      frame.getContentPane().add(panel, BorderLayout.CENTER);    
   }  
}

Forget the question, my fault. The correct commands are;

 javac SwingTester.java
 java SwingTester

I forgot to check my reminder and asked in the wrong order.

Now I have to find how to generate the application (instead of running it in the Terminal).

Once I choosed an image file I get:

Simple question: why not with the Netbeans IDE and the Screen Designer but hand coded what is a bit harder to do? Only as a mention. The example works without any problem like you see.

Because there is no MacOS (nor Apple arm) version available ?

Google propose me to downlad version 12.2 as dmg.

MacBook Pro 13" m1
Sonoma 14.3.1

java -version
java version “21.0.2” 2024-01-16 LTS
Java™ SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot™ 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)

Take the platform independent one. And install java 21 idk from Azul. The platform installers will come the next few days also.

Thank you for your answer Thorsten. As you can see, things are not so easy :(.

Netbeans v 20 nor 19 are not available for MacOS…

I know about Abdul (never heard about abdul, nor idk).

And, yes, after waiting so many years, I can wait for few days…

azul (zulu) installed:

java -version

openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Zulu21.32+17-CA (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Zulu21.32+17-CA (build 21.0.2+13-LTS, mixed mode, sharing)

But no man page for java… in the Terminal.

java --help
will bring you the commends
but for what do you need them for Develöopment?

Normally you can start the IDE and set the IDE settings that you will get the command descriptions all inside the IDE. I do not need any man page when working with IDE.

By the way, pkg is now available for macos install. Just downloaded it and installed without any problem. Runs.

Noe you can start with Java with ant project as a Java application. There y<ou can add a JFrame which you can edit via drag and drop

Hi Thorsten,

I downloaded the pkg…

The stupid guys do not used MacOS, it is a pure hazard that I understand pkg download is for me !

Yes, for development.

I fired it and it looks nice; I do nothing with it (lack of time, I only wanted to be sure it does not asked me to download some more thing “à la Microsoft”…).

Regards,

Emile

Na it needs no downloads or something. When and if you want to use for example Libs via Maven they gert loaded from mavencentral. Only if you want to. And yes, it fires and makes no problems at all.