1

GUIのコーディングの学習を開始しようとしています。概念を把握するには、初めてハンド コードを作成するのが最善であることがわかりました。

私の質問はこれです:これを行うには、Netbeans で GUI ビルダーを無効にする必要がありますか? Netbeans フォーラムを調べましたが、明確な答えが見つかりませんでした。ほとんどのプログラマーは依然としてハンド コーディング オプションを好むようです。

ご清聴ありがとうございました

4

2 に答える 2

2

いいえ、何も無効にする必要はありません。すぐに Swing コードを書き始めることができます。

HelloWorldSwingプログラムのソースを貼り付けて実行してみてください。短縮版は次のとおりです。

import javax.swing.*;        

public class HelloWorldSwing {

    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();
            }
        });
    }
}
于 2012-08-01T09:22:44.940 に答える
0

Swing は何も追加せずに開始できます。例を次に示します。

import javax.swing.JFrame;
import javax.swing.JLabel;


public class HelloWorldFrame extends JFrame {

    //Programs entry point
    public static void main(String args[]) {
        new HelloWorldFrame();
    }

    //Class Constructor to create components
    HelloWorldFrame() {
        JLabel jlbHelloWorld = new JLabel("Hello World");
        add(jlbHelloWorld); //Add the label to the frame
        this.setSize(100, 100); //set the frame size
        setVisible(true); //Show the frame
    }
}

注:これは、非常に単純なバージョンを実行するための最小限のものです... @aioobeはより標準的なアプローチですが、より多くの概念を理解する必要があります:)

于 2012-08-01T09:24:38.393 に答える