目次

【目次】
ブログ内で種別に見たい場合は以下のリンクかラベルから移動してください
イラスト】【動画】【料理】【プログラム

2011年1月28日金曜日

java課題④

とりあえず徹夜しての現状です
頑張ったところはソフトキーボードをプログラム上でいかに1つで済ませられるか!!
「入力キー」で変数に値入れて、ifで場合分けして最終的にどのラベルに入れるかの指定をしました。
うん、もっとスマートにできる気がするね・・・
なんだかなー
仕方がないのは仕方がないけど・・・

あと課題の提出が1限だと思ってたら18:00まででした!!
10時間くらい余裕が!!って2コマ文授業あるから実質6時間くらいですが…
でも余裕ができた!!
友達とかと確認しながらできる時間が!!

とれるといいな…

ソースコードは以下↓!!




import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.GridBagLayout;
import java.awt.CardLayout;
import java.awt.GridBagConstraints;
import java.awt.Dimension;

class kadaireport2 extends JFrame{

JPanel menupanel,cardpanel,cardpanel0,inpanel;// 構造用パネル
JPanel logpanel,panelMain,panelmch,panelmyp;// 画面用パネル
JPanel panel0,panel1;
JLabel label0,label1,labelkey;

//ログイン画面用
JLabel ll0,ll1,ll2,ll3,ll4;
JButton bl0,bl1,bl2,bl3;
JButton button0,button1,button2,button3;
Container container = null;

//動画選択画面用
JPanel mopmain,mop;
JPanel cardmop;
JButton mojb0,mojb1,mojb2,mojb3,mojb4;
JButton mojb[];
JLabel mol;
int i,j;
int nChar = 0;
//動画選択画面用ここまで

GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();

//ソフトキーボード用
int kChar=0;
int a = 0;

// マイページ画面用
JPanel myp0,myp1,myp2,myp3;
JPanel myp20,myp21,myp30,myp31;

JLabel myl20,myl21,myl22;
JLabel myl30,myl31,myl32;

JButton myb20,myb21,myb22;
JButton myb23,myb24;
JButton myb30,myb31,myb32;
JButton myb33,myb34;

public kadaireport2(String title){
super(title);

container = this.getContentPane();

// ログイン画面とその他画面を分ける
cardpanel0 = new JPanel();
cardpanel0.setLayout(new CardLayout());
container.add(cardpanel0);

//ログイン画面
logpanel = new JPanel();
logpanel.setLayout(new GridLayout(3,3,10,10));
cardpanel0.add(logpanel,"login");// ログインパネル名"login"

ll0 = new JLabel("ユーザー名");
logpanel.add(ll0);

ll1 = new JLabel("");
logpanel.add(ll1);
bl2 = new JButton("入力");
bl2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 1;
}
});
logpanel.add(bl2);
ll2 = new JLabel("パスワード");
logpanel.add(ll2);
ll3 = new JLabel("");
logpanel.add(ll3);
bl3 = new JButton("入力");
bl3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 2;
}
});
logpanel.add(bl3);
bl0 = new JButton("ログイン");
bl0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"inpanel");
}
});
logpanel.add(bl0);
bl1 = new JButton("キャンセル");
bl1.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
ll1.setText("");
ll3.setText("");
kChar = 0;
}
});
logpanel.add(bl1);

//ソフトキーボード
JPanel keyp,keyp0;
JButton keyb[],keyb0,keyb1;
String[] aChar3 = {
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z", "@", "-", "_", ".",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

keyp = new JPanel();
keyp.setLayout(new GridLayout(3,1));
cardpanel0.add(keyp,"key");
labelkey = new JLabel("",JLabel.CENTER);
keyp.add(labelkey);

keyp0 = new JPanel();
keyp.add(keyp0);
keyb = new JButton[40];
int k;
Dimension dim = new Dimension();
for(k=0;k <=39;k++){
keyb[k] = new JButton(aChar3[k]);
keyb[k].setPreferredSize(new Dimension(60,25));
keyp0.add(keyb[k]);
keyb[k].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(kChar<8){
JButton btn = (JButton) e.getSource();
if(!btn.getText().equalsIgnoreCase(" ")){
kChar = kChar+1;
String aString = labelkey.getText();
aString = aString + btn.getLabel();
labelkey.setText(aString);
}
}
}
});

}
// 文字列の初期化
keyb1 = new JButton("文字消去");
keyb1.setPreferredSize(new Dimension(180,25));
keyp0.add(keyb1);
keyb1.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
labelkey.setText("");
kChar = 0;
}
});



//決定ボタン
keyb0 = new JButton("決定");
keyb0.setPreferredSize(new Dimension(60,25));
keyp.add(keyb0);
keyb0.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
String aString = labelkey.getText();
if(a==1){
ll1.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"login");
}else if(a==2){
ll3.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"login");
}else if(a==3){
myl20.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"inpanel");
((CardLayout) cardpanel.getLayout()).show(cardpanel,"mypage");
}else if(a==4){
myl21.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"inpanel");
((CardLayout) cardpanel.getLayout()).show(cardpanel,"mypage");
}else if(a==5){
myl22.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"inpanel");
((CardLayout) cardpanel.getLayout()).show(cardpanel,"mypage");
}else if(a==6){
myl30.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"inpanel");
((CardLayout) cardpanel.getLayout()).show(cardpanel,"mypage");
}else if(a==7){
myl31.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"inpanel");
((CardLayout) cardpanel.getLayout()).show(cardpanel,"mypage");
}else if(a==8){
myl32.setText(aString);
a=0;
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"inpanel");
((CardLayout) cardpanel.getLayout()).show(cardpanel,"mypage");
}
labelkey.setText("");
kChar = 0;
}
});
//その他の画面の格納場所
inpanel = new JPanel();
cardpanel0.add(inpanel,"inpanel");

// 上部メニュー画面
menupanel = new JPanel();
menupanel.setLayout(new GridLayout(1,4));
inpanel.add("North",menupanel);

button0 = new JButton("ログイン");
button0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"login");
}
});

menupanel.add(button0);

button1 = new JButton("動画選択");
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel.getLayout()).show(cardpanel,"choose");
}
});
menupanel.add(button1);

button2 = new JButton("マイページ");
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel.getLayout()).show(cardpanel,"mypage");
}
});
menupanel.add(button2);

// 下部メイン画面(カードパネル)
cardpanel = new JPanel();
cardpanel.setLayout(new CardLayout());
inpanel.add("Center",cardpanel);

// 動画選択画面

panelmch = new JPanel();
panelmch.setLayout(new GridLayout(1,2));
cardpanel.add(panelmch,"choose");// 動画選択画面名"choose"

mopmain = new JPanel();
mopmain.setLayout(new GridLayout(6,1,20,10));
mopmain.setPreferredSize(new Dimension(50,400));
panelmch.add("WEST",mopmain);


//動画選択画面のジャンル選択ボタン
JLabel mojl0;
mojl0 = new JLabel("ジャンル選択",JLabel.CENTER);
mopmain.add(mojl0);
mojb0 = new JButton("エンタメ");
mojb0.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
mol.setText("エンタメ");
}
});
mopmain.add(mojb0);
mojb1 = new JButton("ゲーム");
mojb1.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
mol.setText("ゲーム");
}
});
mopmain.add(mojb1);
mojb2 = new JButton("音楽");
mojb2.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
mol.setText("音楽");
}
});
mopmain.add(mojb2);
mojb3 = new JButton("スポーツ");
mojb3.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
mol.setText("スポーツ");
}
});
mopmain.add(mojb3);
mojb4 = new JButton("ニュース");
mojb4.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
mol.setText("ニュース");
}
});
mopmain.add(mojb4);

//動画選択画面各ジャンルパネル
mop = new JPanel();
mop.setLayout(new FlowLayout());
panelmch.add(mop);
mol = new JLabel("");
mop.add(mol);
mojb = new JButton[10];
for(int m = 0;m<=9;m++){
mojb[m] = new JButton("q");
mop.add(mojb[m]);
mojb[m].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel.getLayout()).show(cardpanel,"main");
}
});
}


// 動画表示画面
panelMain = new JPanel();
panelMain.setLayout(layout);
panelMain.setPreferredSize(new Dimension(640,400));
cardpanel.add(panelMain,"main");// 動画表示画面名"movie"
// 動画領域
panel0 = new JPanel();
panel0.setBackground(Color.BLACK);
panel0.setPreferredSize(new Dimension(320,240));
gbc.gridx = 0;
gbc.gridy = 0;
layout.setConstraints(panel0,gbc);
panelMain.add(panel0);
// 動画情報領域
panel1 = new JPanel();
panel1.setBackground(Color.WHITE);
panel1.setPreferredSize(new Dimension(200,240));
gbc.gridx = 1;
gbc.gridy = 0;
layout.setConstraints(panel1,gbc);
panelMain.add(panel1);

// マイページ画面

panelmyp = new JPanel();
panelmyp.setLayout(new GridLayout(2,2));
cardpanel.add(panelmyp,"mypage");// マイページ画面名"mypage"
JButton bm0,bm1;
myp0 = new JPanel();
panelmyp.add(myp0);
myp1 = new JPanel();
panelmyp.add(myp1);
// 投稿用画面
myp2 = new JPanel();
myp2.setLayout(new GridLayout(4,2));
panelmyp.add(myp2);
myl20 = new JLabel("");
myb20 = new JButton("入力");
myb20.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 3;
}
});
myl21 = new JLabel("");
myb21 = new JButton("入力");
myb21.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 4;
}
});
myl22 = new JLabel("");
myb22 = new JButton("入力");
myb22.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 5;
}
});
myb23 = new JButton("上記の動画を投稿");
myb24 = new JButton("キャンセル");
myb24.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
myl20.setText("");
myl21.setText("");
myl22.setText("");
kChar = 0;
}
});
myp2.add(myl20);
myp2.add(myb20);
myp2.add(myl21);
myp2.add(myb21);
myp2.add(myl22);
myp2.add(myb22);
myp2.add(myb23);
myp2.add(myb24);
// 削除用画面
myp3 = new JPanel();
myp3.setLayout(new GridLayout(4,2));
panelmyp.add(myp3);
myl30 = new JLabel("");
myb30 = new JButton("入力");
myb30.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 6;
}
});
myl31 = new JLabel("");
myb31 = new JButton("入力");
myb31.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 7;
}
});
myl32 = new JLabel("");
myb32 = new JButton("入力");
myb32.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
((CardLayout) cardpanel0.getLayout()).show(cardpanel0,"key");
a = 8;
}
});
myb33 = new JButton("上記の動画を削除");
myb34 = new JButton("キャンセル");
myb34.addActionListener(new ActionListener(){
  public void actionPerformed(ActionEvent e){
myl30.setText("");
myl31.setText("");
myl32.setText("");
kChar = 0;
}
});
myp3.add(myl30);
myp3.add(myb30);
myp3.add(myl31);
myp3.add(myb31);
myp3.add(myl32);
myp3.add(myb32);
myp3.add(myb33);
myp3.add(myb34);

this.setSize(640,480);
this.setVisible(true);
}

public static void main(String[] args){
kadaireport2 frame = new kadaireport2("動画視聴サイトインターフェース課題");
}

}



0 件のコメント:

コメントを投稿