• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:色が変わる文字について)

色が変わる文字について

yuizuianの回答

  • yuizuian
  • ベストアンサー率42% (103/245)
回答No.1

g.setColor(new Color(125,125,125)); の部分の数値を変えれば変わると思います。 数値はそれぞれ赤・緑・青に対応しているので、 たとえば255,0,0なら真っ赤に、0,0,0なら真っ黒になるはずです。

関連するQ&A

  • Java applet

    Java appletを使用する課題なのですが、 途中まで書いて、それから止まってしまっています。 アドバイスなど頂ければ嬉しいです。 課題は、 (1)右から左へ動く文字列左から右へ動く文字列とを表示 (2)文字列が消えたらまた出てくるようにする (3)マウスのクリックボタンを押すと止まり、離すと動きだすようにする (2)まで考えたプログラム(コンパイル、実行済)を以下に載せます。 import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class SasakiYui extends Applet implements Runnable{ Thread th = null; Graphics g; int x; public void init(){ setBackground(Color.white); } public void start(){ if(th == null){ th = new Thread(this); th.start(); } } public void run(){ while(!Thread.interrupted()){ for(x=600;x>-300;x=x-5){ repaint(); try{ Thread.sleep(50); } catch(InterruptedException e){} } } } public void paint(Graphics g){ g.drawString("Happy Brithday!",x,10); g.drawString("Happy Birthday!",600-x,40); } } (3)ができるようにするには、 addMouseListener(new Mouseadapter(){ public void mousePressed(MouseEvent e){……} を使用するのだろうとは思うのですが、 ・これを組み込むのはpublic void init(){の後で良いか ・……の部分に何を書けばいいのか の2点がわかりません; よろしければ、アドバイスお願い致します!

    • ベストアンサー
    • Java
  • コンポーネントの組み込みについて

    アプレットでもAWTアプリでもSwingアプリでもなんでもいいんですが、 特定の条件を満たした時に、はじめは表示されていないボタンやテキストフィールドなどを後から表示させたいのですが、できません。 単純にadd()ではできないようで… やり方を教えていただけませんか。。 下は、10秒後にボタンが表示されるように自分で作ってみたサンプルアプレットです。 //<applet code="buttonsample.class" width=300 height=200></applet> import java.applet.*; import java.awt.*; import java.awt.event.*; public class buttonsample extends Applet implements Runnable { int count; //カウント Thread th; //スレッド Button BT; //ボタン public void init() { setLayout(new FlowLayout()); count = 0; BT = new Button(); BT.setLabel("ボタン"); } public void start() { if(th == null) { th = new Thread(this); th.start(); } } public void stop() { th = null; } public void run() { while(count < 10) { repaint(); count++; try { Thread.sleep(1000); } catch(InterruptedException e){} } add(BT); } public void paint(Graphics g) { g.drawString(""+(count+1),100,100); } } <EOS>

    • ベストアンサー
    • 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
  • PacMan

    以下のようなプログラムで自動で動くパックマンを作りました。 パックマンが転がっていくのですが、どうしても目の部分の起動がかけません。 どなたかお力を貸していただけないでしょうか? ================================================= import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.util.*; /* <applet code="PacMan2.class" width="500"height="500"> </applet> */ public class PacMan2 extends Applet implements Runnable { volatile Thread thr; volatile boolean runFlag = true; public void start() { thr = new Thread(this); runFlag = true; thr.start(); } public void stop() { runFlag = false; thr = null; } public void run() { while (runFlag) { repaint(); try { Thread.sleep(1000); //1,000 mili-seconds } catch(InterruptedException e) { runFlag = false; } } } public void paint(Graphics g) { Calendar cal = Calendar.getInstance(); int s = cal.get(Calendar.SECOND); g.setColor(new Color(128,255,255)); g.fillArc(100+s,100,60,60,45-s,300);   g.setColor(new Color(0,0,0)); g.fillOval(130,105,10,10); } } =================================================

    • ベストアンサー
    • Java
  • 音声ファイルの入れ方

    下記ようなじゃんけんゲームでボタンを押した際に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="あなたの負け"; } } }

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

    どうしたらいいのかわからいので、何かヒントで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 applet】他のクラスを呼び出して図形を描写するには

    はじめまして。 非常に簡単なことで、申し訳ないのですが質問させていただきます。 アプレットをextendsしたAppクラスで 他のMakeImgクラスのインスタンス(mi)を 作成し、MakeImgクラスのペイントメソッドを 実行して、図形を描写したいのですが、 下記のプログラムではコンパイルできても 図形が描写されません。 ペイントメソッドは明示的に呼び出さなくても 呼ばれるはずなので図形を描いてくれてもよさそうなのですが。。。 どなたか詳しい方、同じような問題を経験した方がいらっしゃったらぜひ回答していただければと思います。 それではよろしくお願い致します。 ////////////////////////////////////////////// import java.applet.Applet; import java.awt.*; /* <applet code="App.class" width="300"height="300"> </applet> */ public class App extends Applet {  MakeImg mi;  public void init()  {   mi = new MakeImg();  } } class MakeImg {  public void paint(Graphics g)  {   g.setColor(Color.white);   g.fillRect(0 , 0 , 300 , 300);   g.setColor(Color.black);   g.drawString("test",40,30);  } }

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

    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
  • Java Applet での虫食い算での質問

    初めて利用させていただきます。 今、課題で虫食い算のプログラムを作成しているのですが、うまく動作してくれません。 もしよろしければご指摘をしてもらえればと思い書き込みのほうをさせていただきます。 import java.awt.BorderLayout; import java.awt.Button; import java.awt.Color; import java.awt.Event; import java.awt.Font; import java.awt.Graphics; import java.awt.Panel; import java.applet.Applet; public class musikuizan_1 extends Applet { int A, B; int cnt; int sub(int n,int m) { int i; for (i=1; i<m; i++) n /= 10; return n % 10; } void puzzle() { int a; int b; int c; int d; int e; for (a=1; a<=99; a++) { for (b=1; b<=99; b++) { c = a * (b % 10); d = a * (b / 10); e = a * b; if (c>=100 && c<=999 && d>=10 && d<=99 && e>=100 && e<=999) /*桁数調整*/ { if (sub(b,1)==3 && sub(c,2)==1 && sub(d,2)==8) /*穴埋めされてある部分の数*/ { A = a; B = b; cnt++; } } } } } public void init() { setBackground(new Color(150,180,200)); setLayout(new BorderLayout()); Panel psouth = new Panel(); psouth.add(new Button("実行")); add("South", psouth); } public void paint(Graphics g) { int i, c, d, e; for (i=1; i<=2; i++) { g.drawRect(97-i*20, 5,16,16); g.drawRect(97-i*20,25,16,16); g.drawRect(77-i*20,65,16,16); } for (i=1; i<=3; i++) { g.drawRect(97-i*20,45,16,16); g.drawRect(97-i*20,85,16,16); } for (i=1; i<=4; i++) g.drawLine(30,43,100,43); g.drawLine(30,83,100,83); g.setFont(new Font("Helvetica",Font.BOLD,18)); g.drawString("x",40, 40); if (A == 0) { g.drawString("3",60, 40); g.drawString("1",60, 60); g.drawString("8",60, 80); g.setFont(new Font("Helvetica",Font.PLAIN,12)); g.drawString("cnt = ",30,115); } else { c = A * (B % 10); d = A * (B / 10); e = A * B; g.setFont(new Font("Helvetica",Font.BOLD,18)); for (i=1; i<=2; i++) { g.drawString(Integer.toString(sub(A,i)),100-i*20, 20); g.drawString(Integer.toString(sub(B,i)),100-i*20, 40); } for (i=1; i<=3; i++) { g.drawString(Integer.toString(sub(c,i)),100-i*20, 60); g.drawString(Integer.toString(sub(d,i)), 80-i*20, 80); } for (i=1; i<=4; i++) g.drawString(Integer.toString(sub(e,i)),100-i*20,100); g.setFont(new Font("Helvetica",Font.PLAIN,12)); g.drawString("cnt = "+Integer.toString(cnt),30,115); } } public boolean action(Event e, Object arg) { if ("実行".equals(arg)) { if (A == 0) puzzle(); else A = cnt = 0; repaint(); } return true; } }

    • ベストアンサー
    • Java
  • 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