株式会社アイネックスはソフトウェアの開発、ホームページの作成ツール企業です。

     横浜、東京に拠点を置き、検証システム/金融・証券のシステム等の構築、開発を行い、
ホームページの作成ツール支援と多岐にわたるソリューションを提供します。

ラズベリーパイ

40-02) ラズベリーパイ JAVA(Swing)

JAVA(Swing)

Java(Swing)の簡単な例を用いて、Swingのイメージを理解する。

40-02) 1.Javaプログラムの新規作成

Javaプログラムの新規作成
 [プロジェクト] 選択
 [新規クラス]  ボタンを押下し、プログラムソースを入力する。


らずべりー

40-02) 2.JAVA(Swing)のサンプルソース

import java.awt.*;
import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.border.*;
import java.awt.event.*;

public class Taku201 extends JFrame {

private JPanel contentPane;
private JLabel label_1;
private JLabel label_2;
private JButton button;
private JTextField text_moji;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Taku201 frame = new Taku201();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public Taku201() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(null);
setContentPane(contentPane);

label_1 = new JLabel("入力されたテキストの表示確認");
label_1.setFont(new Font("MS UI Gothic", Font.PLAIN, 16));
label_1.setBounds(77, 52, 259, 34);
contentPane.add(label_1);

label_2 = new JLabel("表示するテキスト");
label_2.setBounds(50, 121, 115, 22);
contentPane.add(label_2);

text_moji = new JTextField();
text_moji.setBounds(164, 119, 214, 28);
contentPane.add(text_moji);
text_moji.setColumns(10);

button = new JButton("表示する");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String smoji = text_moji.getText();
/* 表示するパネル */
JOptionPane.showMessageDialog(null, smoji, "確認文字",
JOptionPane.INFORMATION_MESSAGE);
/* 文字のクリア */
text_moji.setText("");

}
});
button.setBounds(112, 189, 122, 34);
contentPane.add(button);

}
}


Javaソースの整形は 編集 → Auot layout を利用してください。 

らずべりー

40-02) 3.JAVA(Swing)プログラムの実行

1.Javaプログラムのコンパイル
 [コンパイル] ボタンをを押下する

2.Javaプログラムの実行
 [作成したクラス] を右クリックして、void main を選択する。

簡単な Swing画面の 表示するテキストに入力されたデータを
確認文字の画面に表示する。

らずべりー