Δημοσιεύτηκε: 09 Ιουν 2015, 17:27
Το γνωστό hello world χωρίς γραφικά
σε Swing
σε java fx
Για μένα βιάζεσαι.. Δεν γνωρίζεις αν κατάλαβα καλά java και αντικειμενοστραφή προγραμματισμό και θες να πας στα γραφικά.
Είναι τελείως λάθος. Φιλικά πάντα
- Κώδικας: Επιλογή όλων
public class HelloWorld {
public static void main(String args[]){
System.out.println("Hello World");
}
}
σε Swing
- Κώδικας: Επιλογή όλων
import javax.swing.*;
public class HelloWorldSwing {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add the ubiquitous "Hello World" label.
JLabel label = new JLabel("Hello World");
frame.getContentPane().add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
σε java fx
- Κώδικας: Επιλογή όλων
package helloworld;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
Για μένα βιάζεσαι.. Δεν γνωρίζεις αν κατάλαβα καλά java και αντικειμενοστραφή προγραμματισμό και θες να πας στα γραφικά.
Είναι τελείως λάθος. Φιλικά πάντα