質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

解決済

1回答

955閲覧

!!!問題丸投げです。大丈夫な方のみお願いします。!!! Javaを使用した簡易アニメーションのプログラム穴埋め問題

Akyan

総合スコア5

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2021/04/17 04:09

編集2021/04/17 04:48

赤い円の半径が10~100まで変化するアニメーションの穴埋め問題です。半径が100に達した場合は、10に戻る使用です。よろしくお願いします。

import java.awt.Canvas; import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.Point; import java.awt.image.BufferedImage; /** * Animation using AWT, Thread and double buffering */ public class ExAWTAnimation extends Frame implements Runnable{ //== Parameters of the animation figure =================== //========================================================= // Image data for double buffering private final BufferedImage buffer = new BufferedImage(420, 300, BufferedImage.TYPE_INT_BGR); // The canvas object to show animation figure on the window private final Animation_CVS cvs = new Animation_CVS(); // An inner canvas class private final class Animation_CVS extends Canvas { // Method paint() will be automatically invoked when needed // paint() is for creating one frame of the animation @Override public void paint(final Graphics gCanvas){ // Get the Graphics of the buffer Graphics gBuffer = buffer.getGraphics(); // Clear the buffer by white color gBuffer.setColor(Color.white); gBuffer.fillRect(0, 0, 420, 300); //========================================================= // Use gBuffer to draw the figure on the buffer // (The parameters in the attributes should be used here) //========================================================= // Copy the buffer to the canvas gCanvas.drawImage(buffer, 0, 0, null); } } // Method run() is required since your Frame class declares to implement Runnable interface // We use run() to control the drawing on the canvas. @Override public void run(){ try { // Repeat following: while(true){ // Sleep for 0.1 second Thread.sleep(100); //========================================================= // Change the parameters of the animation figure for next frame of the animation //========================================================= // This is to invoke the paint() method of the canvas object to draw next frame cvs.repaint(); } } catch (Exception ex) { } } /** * Constructor * @param title the title of the window */ public ExAWTAnimation(String title){ super(title); add(cvs); setSize(420,300); new Thread(this).start(); } public static void main(String[] args){ new ExAWTAnimation("Ex#2: Step 1").setVisible(true); } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

1T2R3M4

2021/04/17 04:20

質問は何でしょうか。
dodox86

2021/04/17 04:48

たぶん勘違いされているのかと思いますが、ここは問題を投げると自動的に誰かが片付けてくれるようなサイトではありません。 [推奨していない質問] https://teratail.com/help/avoid-asking
Akyan

2021/04/17 04:49

丸投げなことを明記しませんでした。不快に思われたならすみません。スルーしてください。
Zuishin

2021/04/17 04:51

明記すればいいというものではない。
dodox86

2021/04/17 04:52

[2021/04/17 13:48]の質問編集を読んで > !!!問題丸投げです。大丈夫な方のみお願いします。!!! J 驚くべきことに勘違いではなかったご様子。きりが無いのと、既に現時点で低評価が4なので、私からは低評価はせず、スルーしておきます。
guest

回答1

0

自己解決

よくわからなかったのですが、足りなさそうな部分を足したらできました。不快に思われた方、すみませんでした。次回からは、自分でやってから質問します。

import java.awt.Canvas; import java.awt.Color; import java.awt.Frame; import java.awt.Graphics; import java.awt.Point; import java.awt.image.BufferedImage; /** * Animation using AWT, Thread and double buffering */ public class ExAWTAnimation extends Frame implements Runnable{ //== Parameters of the animation figure =================== int x = 100; int centerx = 100 + (100 - x) + x; int centery = 50 + (100 - x) + x; //========================================================= // Image data for double buffering private final BufferedImage buffer = new BufferedImage(420, 300, BufferedImage.TYPE_INT_BGR); // The canvas object to show animation figure on the window private final Animation_CVS cvs = new Animation_CVS(); // An inner canvas class private final class Animation_CVS extends Canvas { // Method paint() will be automatically invoked when needed // paint() is for creating one frame of the animation @Override public void paint(final Graphics gCanvas){ // Get the Graphics of the buffer Graphics gBuffer = buffer.getGraphics(); // Clear the buffer by white color gBuffer.setColor(Color.white); gBuffer.fillRect(0, 0, 400, 300); //========================================================= // Use gBuffer to draw the figure on the buffer // (The parameters in the attributes should be used here) gBuffer.setColor(Color.red); gBuffer.drawOval(100+(100-x), 50+(100-x), x*2, x*2); gBuffer.setColor(Color.black); gBuffer.drawString("The circle :",150,130); gBuffer.drawString("center = " + centerx + "," + centery,150,160); gBuffer.drawString("radius = " + x ,150,190); //========================================================= // Copy the buffer to the canvas gCanvas.drawImage(buffer, 0, 0, null); } } // Method run() is required since your Frame class declares to implement Runnable interface // We use run() to control the drawing on the canvas. @Override public void run(){ try { // Repeat following: while(true){ // Sleep for 0.1 second Thread.sleep(100); //========================================================= // Change the parameters of the animation figure for next frame of the animation if(x > 10){ x--; }else{ x = 100; } //========================================================= // This is to invoke the paint() method of the canvas object to draw next frame cvs.repaint(); } } catch (Exception ex) { } } /** * Constructor * @param title the title of the window */ public ExAWTAnimation(String title){ super(title); add(cvs); setSize(400,300); new Thread(this).start(); } public static void main(String[] args){ new ExAWTAnimation("Ex#2: Step 1").setVisible(true); } }

投稿2021/04/17 05:17

Akyan

総合スコア5

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問