HttpPost クラスのテストです。超簡易掲示板(CSV)は以下からダウンロードできます。 超簡易掲示板 : 保存タイプは CSV WindowBuilder 側では、複数行のテキストフィールドを使って単純投稿です。
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.google.gson.Gson;
public class TopWindow extends ApplicationWindow {
private int width = 600;
private int height = 440;
private Gson gson;
private Text text;
// *********************************
// コンストラクタ
// *********************************
public TopWindow() {
super(null);
}
// *********************************
// コントロールの追加
// ※ Design での変更が反映されます
// *********************************
@Override
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
// ボタンの定義
Button button = new Button(container, SWT.NONE);
// ボタンのイベント
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// プログラム開始時に実行すると、固まるので直前に
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException | InstantiationException
| IllegalAccessException
| UnsupportedLookAndFeelException e1) {
e1.printStackTrace();
}
// 確認ダイアログ( OK_CANCEL )の表示
int result = JOptionPane.showConfirmDialog(
null,
"データを POST しますか",
"確認",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
// OK を選択
if ( result == JOptionPane.OK_OPTION ) {
// POST データ
Map<String,String> param = new HashMap<String,String>();
param.put("send", "send");
param.put("subject", "テスト投稿");
param.put("name", "ウインドウビルダー");
param.put("text", text.getText());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
param.put("datetime", sdf.format(new Date()));
// インターネットアクセス
String data = HttpPost.execute("http://localhost/log/easy_board/csvtype/board.php", param, "utf-8");
// データを取得できた
if ( !data.equals("") ) {
// コンソールで確認
System.out.println(data);
}
}
}
});
button.setBounds(10, 10, 81, 28);
button.setText("実行");
text = new Text(container, SWT.BORDER | SWT.MULTI);
text.setBounds(10, 44, 483, 341);
return container;
}
// *********************************
// アプリケーションの開始
// *********************************
public static void main(String args[]) {
try {
// 自分自身(TopWindow) の作成
TopWindow window = new TopWindow();
// open を実行したら、Window を閉じるまで次の行を実行しない
window.setBlockOnOpen(true);
window.open();
// Window を閉じたら以下を実行してアプリケーションを終了する
Display.getCurrent().dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
// *********************************
// Window の初期設定
// *********************************
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
// タイトルの設定
newShell.setText("タイトル文字列");
}
// *********************************
// Window サイズの初期設定
// *********************************
@Override
protected Point getInitialSize() {
// プライベート変数を使用してウインドウサイズを決定しています
return new Point(width, height);
}
}
プロジェクトを一から作る方法
|
|
【java : WindowBuilderの最新記事】
- WindowBuilder JFace : WEB より JSON を取得して Table に表示する
- Pleiades All in One で、Windows アプリを作成する手順( WindowBuilder + Swing デザイナー or SWT デザイナー[JFace] )
- WindowBuilder(Swing) で、WEBカメラを使用して画像を保存して okhttp で WEBサーバへアップロードする
- WindowBuilder のテーブルコントロールにインターネットから JSON データを読み込んで処理するテンプレート
- WindowBuilder テンプレートのテーブルコントロールに MySQL のデータを表示する
- Eclipse 4.4 Pleiades + WindowBuilder テンプレート / アプリケーションウインドウとダイアログ / インポート手順


超簡易掲示板(CSV)は以下からダウンロードできます。




