• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:JAVAのプロフラミングについて)

JAVAのプロフラミングについて

komi1341の回答

  • komi1341
  • ベストアンサー率65% (25/38)
回答No.3

> また、if文は、つけてみたのですが、 > 実行してみたら、エラーになってしまいました。 あのですね、 > if(){ このまま書いたらそりゃコンパイルエラーになりますよ。if文をどう書くかも勉強していないのですか? めちゃくちゃ基礎ですよ? この問題は、ifのカッコの中に必要な条件判定を入れる、という穴埋め問題だと思います。それを「if()と書いたらエラーになった」というレベルの質問をしているようでは、回答者側は一からあなたにJavaを教えるか、答えを丸ごと書いてあげなければいけません。どちらも無料で他人に頼むことではありません。少なくとも「質問と回答」というレベルのやりとりでは、この問題は解決しませんよ。 悪いことは言わないので、Javaを一から勉強してください。まったく基礎が分かっていない人に答えだけ提示しても無駄なので。if文の書き方なんて、勉強本の最初の方に載っていると思いますよ。

関連するQ&A

  • JAVAのプログラミングについて

    色変更というボタンを押すたびに、正方形の中の色が緑から青、青から緑というように繰り返し色が変わるプログラムを作りたいのですが、途中までは、完成できたのですが、ここからどうすればいいかわかりません。教えてください。 import java.awt.*; import java.applet.*; import java.awt.event.*; public class kadai3Applet extends Applet implements ActionListener { int i = 1; Button collor; public void init(){ collor = new Button("色変更"); collor.addActionListener(this); add(collor); } public void paint(Graphics g){ g.setColor(Color.green); g.fillRect(50,50,50,50); } public void actionPerformed(ActionEvent e){ if(e.getSource() == collor){ } repaint(); } }

  • jcpad

    『長方形をあらかじめ置き、、縮小、拡大のボタンを押すことで  縦横を1/1.05倍に縮小できるようにする』 という問題が教科書にあり、拡大、縮小ボタンを作るまではできたのですがそれ以降がうまく考えることができません。 //<applet code= "Counter3.class" width=300 height=150></applet> import java.awt.*; import java.applet.*; import java.awt.event.*; public class Counter3 extends Applet implements ActionListener { Font font; Button kakudaiButton, syukushoButton; public void init() { font = new Font("Serif", Font.BOLD, 72); kakudaiButton = new Button("拡大"); kakudaiButton.addActionListener(this); add(kakudaiButton); syukushoButton = new Button("縮小"); syukushoButton.addActionListener(this); add(syukushoButton); } public void paint(Graphics g) { g.drawOval(); } public void actionPerformed(ActionEvent e) { if (e.getSource() == kakudaiButton) { ; } else if (e.getSource() == syukushoButton) { ; } repaint(); } }

  • 音声ファイルの入れ方

    下記ようなじゃんけんゲームでボタンを押した際にwav拡張子の音声ファイルを再生したいのですがどのようにすればよいでしょうか import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.File; import javax.sound.sampled.*; public class janken extends Applet implements Runnable, ActionListener { private static final int EXTERNAL_BUFFER_SIZE = 128000; Image image[] = new Image[3]; Thread t; int index1 = 0; int index2 = 0; String msg = ""; String msg1 = ""; boolean state = false; Button b1 = new Button("ぐー"); Button b2 = new Button("ちょき"); Button b3 = new Button("ぱー"); public void init(){ for(int i = 0; i<=2; i++){ image[i] = getImage(getDocumentBase(),"hanabi" + (i+1) + ".JPG"); } add(b1); add(b2); add(b3); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); msg1 = "結果は・・"; } public void paint(Graphics g){ g.drawImage(image[index1],350,30,this); g.drawImage(image[index2],745,30,this); g.drawString("わたし",420,300); g.drawString("あなた",820,300); g.drawString(msg,630,320); g.drawString(msg1,550,320); }  public void start(){  state = true;  t = new Thread(this); t.start(); } public void run(){ while(state){ index1++; if(index1 == 3){ index1 = 0; } index2++; if(index2 == 3){ index2 = 0; } repaint(); try { Thread.sleep(60); }catch(InterruptedException e) { } } } public void actionPerformed(ActionEvent e){ if(state == false) { start(); return; } state = false; if(e.getSource() == b1) { msg = "ぐー"; index2 = 0; } else if(e.getSource() == b2){ msg = "ちょき"; index2 = 1; } else if(e.getSource() == b3){ msg = "ぱー"; index2 = 2; } check(); repaint(); } public void check() { if(index1 == index2) msg ="あいこ"; else if (index1 == 0) { if(index2 == 2) msg="あなたの勝ち"; else msg ="あなたの負け"; } else if(index1 == 1) { if(index2 == 0) msg="あなたの勝ち"; else msg="あなたの負け"; } else if(index1 == 2) { if(index2 == 1) msg="あなたの勝ち"; else msg="あなたの負け"; } } }

  • HTMLファイルを開きたい

    こんにちは、いつもお世話になっています。 質問があります。 アプレットでボタンを押すと、 HTMLファイル「c:/test_folder/test.html」 を開きたいのですが、 下記コードの(☆) のところに何を書いていいかわかりません。 どなたかご存知でしたら教えていただけないでしょうか? よろしくお願いします。 ============================================================= import javax.swing.*; import java.awt.*; import java.applet.Applet; import java.awt.event.*; import java.net.*; public class situmon extends Applet implements ActionListener { JPanel panel; JButton button; public void init() { panel=new JPanel(); button=new JButton("次へ"); button.addActionListener(this); panel.add(button); this.add(panel); } public void actionPerformed(ActionEvent e) { if(e.getSource()==button) { (☆); } } }

    • ベストアンサー
    • Java
  • シンボルが見つかりませんというエラーが理解できません。

    以下のようなじゃんけんゲームのプログラムを書いたのですが、「シンボルが見つかりません。」というエラーが表示されるのですが、エラーの意味が理解できず、解決できません。どこが間違っているのか教えていただけませんか。 import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.File; public class janken extends Applet implements Runnable, ActionListener { private static final int EXTERNAL_BUFFER_SIZE = 128000; Image image[] = new Image[3]; Thread t; int index1 = 0; int index2 = 0; String msg = ""; String msg1 = ""; boolean state = false; Button b1 = new Button("ぐー"); Button b2 = new Button("ちょき"); Button b3 = new Button("ぱー"); public void init(){ for(int i = 0; i<=2; i++){ img[i] = getImage(getDocumentBase(),"hanabi" + (i+1) + ".JPG"); } add(b1); add(b2); add(b3); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); msg1 = "結果は・・"; } public void paint(Graphics g){ g.drawImage(img[index1],350,30,this); g.drawImage(img[index2],695,30,this); g.drawString("コンピューター",420,300); g.drawString("あなた",800,300); g.drawString(msg,630,320); g.drawString(msg1,550,320); } public void start(){ state = true; t = new Thread(this); t.start(); } public void run(){ while(state){ index1++; if(index1 == 3){ index1 = 0; } index2++; if(index2 == 3){ index2 = 0; } repaint(); try { Thread.sleep(60); }catch(InterruptedException e) { } } } public void actionPerformed(ActionEvent e){ if(state == false) { start(); return; } state = false; if(e.getSource() == b1) { msg = "ぐー"; index2 = 0; } else if(e.getSource() == b2){ msg = "ちょき"; index2 = 1; } else if(e.getSource() == b3){ msg = "ぱー"; index2 = 2; } check(); repaint(); } public void check() { if(index1 == index2) msg ="あいこ"; else if (index1 == 0) { if(index2 == 2) msg="あなたの勝ち"; else msg ="あなたの負け"; } else if(index1 == 1) { if(index2 == 0) msg="あなたの勝ち"; else msg="あなたの負け"; } else if(index1 == 2) { if(index2 == 1) msg="あなたの勝ち"; else msg="あなたの負け"; } } }

    • ベストアンサー
    • Java
  • Javaアプレットについてですが

    Javaアプレットでボタンを押したら数字が増えるものを作っているのですがどうもうまく動きません。 ソースは下の通りです。 変更しなければいけないところがあるならお願いします。 import java.applet.Applet; import java.awt.Graphics; import java.awt.Button; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Sample7 extends Applet implements Runnable, ActionListener { Button bt; int num; public void init() { bt = new Button("開始"); add(bt); bt.addActionListener(this); Thread th; th = new Thread(this); th.start(); } public void actionPerformed(ActionEvent ae) { public void run() { try{ for(int i=0; i<11; i++){ num = i; repaint(); Thread.sleep(1000); } } catch(InterruptedException e){} } } public void paint(Graphics g) { String str = num + "です。"; g.drawString(str, 50, 50); } }

    • ベストアンサー
    • Java
  • 画面のちらつきの原因が知りたいです

    JAVAの初心者です、宜しくお願いします。 下のようなプログラムを書きました。 「public void paint(Graphics g){ ~ repaint();」とすると、画像がちらつきます、しかし、「repaint();」を消すとちらつかなくなります、この原因が分かりません。 一体何故このような現象が起こるのでしょうか、宜しくお願いします。 ========================================================== import java.applet.Applet; import java.awt.Button; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; public class Oval_Rec_1_071128 extends Applet implements MouseListener , ActionListener { int x1 ; int y1 ; int xh = 50 ; int yv = 50 ; Button bt1 ; Button bt2 ; public void actionPerformed(ActionEvent ae){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void init() { setBackground(Color.yellow); addMouseListener(this); bt1 = new Button("push"); bt1.setFont(new Font("SansSerif", Font.BOLD, 20)); bt1.setBackground(Color.black); bt1.setForeground(Color.lightGray); add(bt1); bt1.addActionListener(this); bt2 = new Button("change_circle"); add(bt2); bt2.addActionListener(this); } public void mousePressed(MouseEvent e) { x1 = e.getX(); y1 = e.getY(); xh = e.getX(); yv = e.getY(); // repaint(); //comment out } public void paint(Graphics g) { g.setColor(Color.red); g.setFont(new Font("Serif",Font.BOLD,24)); g.drawString("Hello Applet World ! !" , 50 , 50); g.setColor(Color.blue); g.drawLine( 100 , 100 , 500 , 500); g.setColor(Color.cyan); g.fillOval( x1 , y1 , xh , yv); g.setColor(Color.magenta); g.fillRect( xh , yv, x1/10 , y1/10 ); repaint(); } }

    • ベストアンサー
    • Java
  • ペイントソフトでキャンバス内にだけにかけるようにしたいです。

    どうしたらいいのかわからいので、何かヒントでiいので教えてください。 import java.applet.*; import java.awt.*; import java.awt.event.*; /* <APPLET CODE ="Mous" WIDTH = 500 HEIGHT = 300> </APPLET> */ public class Mous extends Applet { Graphics g; int point_x, point_y; Button color_black,color_red,color_blue,clear; public void init() { g = getGraphics(); setLayout(null); addMouseListener(new MouseAdapter () { public void mousePressed(MouseEvent e){ point_x = e.getX(); point_y = e.getY(); } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { g.drawLine(point_x,point_y,e.getX(),e.getY()); point_x = e.getX(); point_y = e.getY(); } }); color_black = new Button("黒"); color_black.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { g.setColor(Color.black); } }); color_red = new Button("赤"); color_red.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { g.setColor(Color.red); } }); color_blue = new Button("青"); color_blue.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { g.setColor(Color.blue); } }); clear = new Button("クリアー"); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { g.clearRect(0,0,500,300); } }); add(color_black); add(color_red); add(color_blue); add(clear); } }

  • JAVAのアプレットのアニメーションの質問

    javaのアプレットに関する質問なんですが、今次の条件でアニメーションを作っているんですが、どうしても解決できない問題があります。 赤い長方形が左から右に動いていくプログラムを作成する。 ・ 長方形が描画領域 の右端に消えると左端から再 度出現するようにせよ。 ・ Reverseと書かれたボタンを押すと長方形の進行方 向が左右反対になる。 ・ このとき、左右どちらの端に長方形が消えた場合も 反対端から長方形は出現する。 ・ 長方形をクリック(ボタン押下)すると長方形の色が 変化する。 ・ 赤い長方形であれば青に、青い長方形であれば赤 に変化する。 この条件でつくろうと思っているのですが、長方形をクリックしたときに、色の変化がどうしてもできません。どこに問題があるか分かりません。御教授お願いします。 import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; import java.awt.Font; import java.awt.Button; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.MouseListener; public class Report2 extends Applet implements Runnable,ActionListener,MouseListener{ int x=100; int y=50; int width=80; int height=120; int dir=-2; int w; int z; Button bt; boolean direction; boolean colorRed; public void actionPerformed(ActionEvent ae){ if(direction==true){ direction=false; } else{ direction=true; } } public void init(){ bt=new Button("Reverse"); add(bt); bt.addActionListener(this); Thread th; th =new Thread(this); th.start(); addMouseListener(this); } public void mouseClicked(MouseEvent e){ w=e.getX(); z=e.getY(); repaint(); if(e.getX()>=x && e.getX()<=x+width && e.getY()>=y && e.getY()<=y+height){ colorRed=!colorRed; } } public void mouseEntered(MouseEvent e){ } public void mouseExited(MouseEvent e){ } public void mouseReleased(MouseEvent e){ } public void mousePressed(MouseEvent e){ w=e.getX(); z=e.getY(); repaint(); if(e.getX()>=x && e.getX()<=x+width && e.getY()>=y && e.getY()<=y+height){ colorRed=!colorRed; } } public void run() { while(true){ x++; if(x==400){ x=-80; } if(direction==true){ x=x+dir; } else{ } repaint(); try{ Thread.sleep(30); } catch(InterruptedException e){} } } public void paint(Graphics g){ g.setColor(Color.white); g.fillRect(0,0,400,200); g.setColor(Color.red); g.fillRect(x,y,80,120); if(colorRed=true){ g.setColor(Color.red); } if(colorRed=false){ g.setColor(Color.blue); } g.fillRect(x,y,width,height); g.setColor(Color.black); g.fillRect(x,y,10,10); } }

    • ベストアンサー
    • Java
  • アクションリスナー(初心者です)

    JAVAでボタンが押されたらすでに描かれている線に さらに線が加わって描かれるというプログラムを作ろうとしているのですが、アクションリスナーを受け取ったメソッドの中身をどうしたらいいのか行き詰まりました・・・作りかけのプログラムを載せてみますので アドバイスいただければと思います よろしくお願いします import java.applet.Applet; import java.awt.Graphics.*; import java.awt.event.*; import java.awt.*; public class file928 extends Applet implements ActionListener { Button botan; public void init() { botan=new Button("選択"); add(botan); botan.addActionListener(this); } public void paint(Graphics g) { g.drawString("L.A.Airport",100,300);           ~中略~ g.drawLine(405,420,655,240); } public void actionPerformed(ActionEvent x) { ーここをどうしたらいいかわかりません・・・ー } }

    • ベストアンサー
    • Java