|
|
12/22(Sun) 03:12
■ 日時表示、ボタンやポップアップメニュー、テキストフィールドをつける
■やりたいこと
- ステータスパネルにポップアップメニューやテキストフィールドをつける。
- ながめる方角は、東西南北の4つとする
- 観測地選択または緯経度入力を可能とする
- 日時を指定すれば、その時の星空を表示する
- コントロールパネルにボタンやポップアップメニューをつける。
- 日周運動(速度可変)を表示する
- 星名、星座名&星座線、航跡の表示・非表示選択を可能とする
- 天球の直径をパラメータとし表示サイズを可変にする
■ ソースリスト (注)このソースは作成途中のものですが上記アップレットの表示ができます(左クリックでソース表示、右クリックでファイル保存です)
/***************************************************************
* 星空ウォッチング(プラネタリウム) *
* by「菊池さん」 *
**************************************************************/
import java.applet.Applet;
import java.awt.*;
import java.util.Date;
//描画
class drawing1 extends Canvas {
public void paint(Graphics draw_panel) {
int R = 600; //天球の半径
int offsetX = 10; //横両サイドのりしろ
int offsetY = 20; //縦両サイドのりしろ
int msize = 12; //表示文字のサイズ(px)
int X = 200, Y = 150; //星座座標
String seiza_name = "北極星"; //星座名
setSize(R+offsetX*2,R/2+offsetY*2+msize); //サイズ設定
draw_panel.setColor(Color.black);
draw_panel.fillArc(offsetX,offsetY,R,R,0,180); //半天球
draw_panel.setColor(Color.yellow);
draw_panel.fillOval(X,Y,5,5); //星座位置
draw_panel.setColor(Color.white);
draw_panel.drawString(seiza_name, X,Y-4); //星座名
draw_panel.setColor(new Color(230,230,230));
draw_panel.fillRoundRect(offsetX,R/2+offsetY,R,msize,10,5); //方角バー
draw_panel.setColor(Color.red);
draw_panel.drawString("西",offsetX,R/2+offsetY+msize-2); //方角名
draw_panel.drawString("北",R/2+offsetX-msize/2,R/2+offsetY+msize-2);
draw_panel.drawString("東",R+offsetX-msize,R/2+offsetY+msize-2);
}
}
public class sky1 extends Applet {
//日付取得
Date now = new Date();
int year = now.getYear()+1900;
int mon = now.getMonth()+1;
int day = now.getDate();
int wk = now.getDay();
int hour = now.getHours();
int min = now.getMinutes();
String week[] = {"日","月","火","水","木","金","土"};
String datenow = year+"/"+mon+"/"+day;
String hournow = hour+":"+min+"("+week[wk]+")";
//初期値設定
String dir[] = {"北","南","東","西","天頂"};
String city[] = {"稚内","旭川","札幌","根室","釧路","函館","青森"
,"秋田","盛岡","仙台","山形","福島","宇都宮","前橋","水戸","浦和","東京"
,"千葉","横浜","小笠原","新潟","富山","長野","金沢","福井","甲府","岐阜"
,"名古屋","静岡","富士山","京都","大津","津","奈良","大阪","神戸","和歌山"
,"鳥取","松江","岡山","広島","山口","高松","徳島","松山","高知","福岡"
,"佐賀","大分","熊本","長崎","宮崎","鹿児島","那覇"};
String lng[] = {"141°41′","142°22′","141°21′","145°35′"
,"144°24′","140°45′","140°44′","140°07′","141°09′","140°52′"
,"140°21′","140°28′","139°53′","139°04′","140°29′","139°39′"
,"139°45′","140°07′","139°39′","142°11′","139°02′","137°13′"
,"138°11′","136°39′","136°13′","138°34′","136°46′","136°55′"
,"138°23′","138°44′","135°45′","135°52′","136°31′","135°50′"
,"135°29′","135°11′","135°10′","134°14′","133°03′","133°56′"
,"132°27′","131°28′","134°03′","134°33′","132°46′","133°32′"
,"130°24′","130°18′","131°37′","130°43′","129°52′","131°25′"
,"130°33′","127°40′"};
String lat[] = {"45°25′","43°36′","43°04′","43°20′"
,"42°59′","41°49′","40°49′","39°43′","39°42′","38°16′"
,"38°15′","37°45′","36°34′","36°23′","36°22′","35°51′"
,"35°39′","35°36′","35°27′","27°05′","37°55′","36°41′"
,"36°39′","36°34′","36°04′","35°40′","35°25′","35°10′"
,"34°58′","35°21′","35°01′","35°00′","34°44′","34°41′"
,"34°41′","34°41′","34°14′","35°30′","35°28′","34°40′"
,"34°23′","34°11′","34°21′","34°04′","33°50′","33°33′"
,"33°35′","33°15′","33°14′","32°48′","32°45′","31°54′"
,"31°36′","26°13′"};
Panel control_panel = new Panel();
Panel status_panel = new Panel();
Choice choice_motion = new Choice();
Choice choice_direction = new Choice();
Choice choice_city = new Choice();
Choice choice_sign_lng = new Choice();
Choice choice_sign_lat = new Choice();
Button button_draw = new Button("再描画");
Button button_motion = new Button("日周運動開始");
Button button_seiza_name = new Button("星座名表示");
Button button_seiza_line = new Button("星座線表示");
Button button_trace = new Button("航跡表示");
Button button_size_plus = new Button("+");
Button button_size_minus = new Button("−");
TextField textfield_lng = new TextField(lng[0],10);
TextField textfield_lat = new TextField(lat[0],10);
TextField textfield_date = new TextField(datenow,10);
TextField textfield_hour = new TextField(hournow,10);
public void init() {
//背景・描画色とレイアウト設定
setBackground(new Color(0,0,192));
setForeground(new Color(0,0,0));
setLayout(new BorderLayout());
//天球
add("Center",new drawing1());
//ステータスパネル
status_panel.setLayout(new GridLayout(2,1));
status_panel.setBackground(new Color(192,192,192));
status_panel.add(new Label("方角:",Label.RIGHT));
for (int i = 0; i < dir.length; i++) choice_direction.addItem(dir[i]);
status_panel.add(choice_direction);
status_panel.add(new Label("経度:",Label.RIGHT));
choice_sign_lng.addItem("E");
choice_sign_lng.addItem("W");
status_panel.add(choice_sign_lng);
status_panel.add(textfield_lng);
status_panel.add(new Label("日付:",Label.RIGHT));
status_panel.add(textfield_date);
status_panel.add(new Label(""));
status_panel.add(new Label("観測地:",Label.RIGHT));
for (int i = 0; i < city.length; i++) choice_city.addItem(city[i]);
status_panel.add(choice_city);
status_panel.add(new Label("緯度:",Label.RIGHT));
choice_sign_lat.addItem("N");
choice_sign_lat.addItem("S");
status_panel.add(choice_sign_lat);
status_panel.add(textfield_lat);
status_panel.add(new Label("時刻:",Label.RIGHT));
status_panel.add(textfield_hour);
status_panel.add(button_draw);
add("North",status_panel);
//コントロールパネル
control_panel.setBackground(new Color(0,192,192));
control_panel.add(button_motion);
control_panel.add(new Label("速度:",Label.RIGHT));
for (int i = 0; i < 10; i++) choice_motion.addItem(String.valueOf(i+1));
control_panel.add(choice_motion);
control_panel.add(button_seiza_name);
control_panel.add(button_seiza_line);
control_panel.add(button_trace);
control_panel.add(new Label("表示サイス:",Label.RIGHT));
control_panel.add(button_size_plus);
control_panel.add(button_size_minus);
add("South",control_panel);
}
//イベント処理
public boolean action(Event evt, Object arg) {
if (evt.target instanceof Button) {
if (arg.equals("日周運動開始")) {
button_motion.setLabel("日周運動停止");
System.out.println("日周運動開始 pressed!");
} else if (arg.equals("日周運動停止")) {
button_motion.setLabel("日周運動開始");
System.out.println("日周運動停止 pressed!");
} else if (arg.equals("星座名表示")) {
button_seiza_name.setLabel("星座名消去");
System.out.println("星座名表示 pressed!");
} else if (arg.equals("星座名消去")) {
button_seiza_name.setLabel("星座名表示");
System.out.println("星座名消去 pressed!");
} else if (arg.equals("星座線表示")) {
button_seiza_line.setLabel("星座線消去");
System.out.println("星座線表示 pressed!");
} else if (arg.equals("星座線消去")) {
button_seiza_line.setLabel("星座線表示");
System.out.println("星座線消去 pressed!");
} else if (arg.equals("航跡表示")) {
button_trace.setLabel("航跡消去");
System.out.println("航跡表示 pressed!");
} else if (arg.equals("航跡消去")) {
button_trace.setLabel("航跡表示");
System.out.println("航跡消去 pressed!");
} else if (arg.equals("+")) {
System.out.println("+ pressed!");
} else if (arg.equals("−")) {
System.out.println("− pressed!");
} else if (arg.equals("再描画")) {
System.out.println("再描画 pressed!");
}
return true;
} else if (evt.target instanceof Choice) {
for (int i = 0; i < city.length; i++) {
if (arg == city[i]) {
textfield_lng.setText(lng[i]);
textfield_lat.setText(lat[i]);
break;
}
}
return true;
} else if (evt.target instanceof TextField) {
System.out.println(textfield_lng.getText());
return true;
}
return false;
}
}
|
|
|