Java 问题...希望有高手能帮帮...swing 和 applet 遇到问题... 20
AppropriateuseofidentifiersAppropriatelayoutmanagerCorrectcalculationAppropriateuseof...
Appropriate use of identifiers
Appropriate layout manager
Correct calculation
Appropriate use of swing components
Appropriate class header
Appropriate packages import
Register event listeners
Appropriate event handling
Interface design
Client class
Question
A fishmonger would like to know his total sales from selling his fish produce at the wet market in a day. He sells different types of fish at various prices per kilogram. Write a java applet to help the fishmonger calculate his total sales for the day. Let the farmer enter the type of fish sold and its weight (in kilogram) until he decides to stop entering the data. Calculate the daily sales based on the table given below, and display the total income for each type of fish and the total sales made. Use appropriate swing components in your design.
Types of Fish Price per kg (RM)
Mackerel 12.50
Salmon 26.00
Tuna 16.50
Pomfret 21.70
Red Snapper 24.20 展开
Appropriate layout manager
Correct calculation
Appropriate use of swing components
Appropriate class header
Appropriate packages import
Register event listeners
Appropriate event handling
Interface design
Client class
Question
A fishmonger would like to know his total sales from selling his fish produce at the wet market in a day. He sells different types of fish at various prices per kilogram. Write a java applet to help the fishmonger calculate his total sales for the day. Let the farmer enter the type of fish sold and its weight (in kilogram) until he decides to stop entering the data. Calculate the daily sales based on the table given below, and display the total income for each type of fish and the total sales made. Use appropriate swing components in your design.
Types of Fish Price per kg (RM)
Mackerel 12.50
Salmon 26.00
Tuna 16.50
Pomfret 21.70
Red Snapper 24.20 展开
3个回答
展开全部
类似newThread = new Thread(this);的语句来执行线程。还有就是尽量不要用sleep,用Timer。
============================================
我给你改造了,图片位置不知道正不正确:
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JPanel;
import free.sale;
public class SecondAnimation extends JPanel implements Runnable {
// 错误页面的URL
URL ErrorHTML;
// 目前图像
int currentImage;
// 动画图像
Image Animation[];
// 图像追踪器
MediaTracker MT;
// 新线程
Thread newThread;
public static void main(String[] args) {//这里执行
JFrame frame=new JFrame();
frame.setSize(300, 300);
SecondAnimation sa=new SecondAnimation();
sa.init();
frame.add(sa);
frame.setVisible(true);
sa.start();
}
public void init() {
// 指定目前图像为第一张图像
currentImage = 0;
// 使用八张动画图像
Animation = new Image[7];
MT = new MediaTracker(this);
// *注意此循环中的程序代码*
for (int i = 0; i < 7; i++) {
Animation[i] = this.getToolkit().getImage("Image/lanji"+i+ ".png");
MT.addImage(Animation[i], 0);
}
try {
// 在状态栏显示信息
// showStatus("图像加载中...");
// 等待所有图像下载
MT.waitForAll();
// 若捕捉到异常
} catch (InterruptedException e) {
// 建立错误页面的URL
// try {
// ErrorHTML = new URL(getCodeBase().toString() + "ErrorHTML.html");
// } catch (MalformedURLException e1) {
// }
// // 转移页面
// getAppletContext().showDocument(ErrorHTML);
}
}
// start()函数
public void start() {
newThread = new Thread(this);
newThread.start();
}
// stop()函数
public void stop() {
// 将线程设为null
newThread = null;
}
public void paint(Graphics g) {
// 绘制目前图像
g.drawImage(Animation[currentImage], 50, 10, 250, 250, this);
g.drawString("123456"+"\t"+currentImage, 20, 20);
}
public void run() {
while (newThread != null) {
// 重绘图像
repaint();
try {
// 暂停程序执行125毫秒
Thread.sleep(125);
} catch (InterruptedException e) {
// 建立错误页面的URL
// try {
// ErrorHTML = new URL(getCodeBase().toString()
// + "ErrorHTML.html");
// } catch (MalformedURLException e1) {
// }
// // 转移
// getAppletContext().showDocument(ErrorHTML);
}
// 如果已播放到最后一张图像
if (currentImage == 6)
// 指定目前图像为第一张图像
currentImage = 0;
else
// 指定图像为下一张图像
currentImage = currentImage + 1;
}
}
}
觉得我的回答不错就采纳吧,谢谢了
============================================
我给你改造了,图片位置不知道正不正确:
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
import javax.swing.JPanel;
import free.sale;
public class SecondAnimation extends JPanel implements Runnable {
// 错误页面的URL
URL ErrorHTML;
// 目前图像
int currentImage;
// 动画图像
Image Animation[];
// 图像追踪器
MediaTracker MT;
// 新线程
Thread newThread;
public static void main(String[] args) {//这里执行
JFrame frame=new JFrame();
frame.setSize(300, 300);
SecondAnimation sa=new SecondAnimation();
sa.init();
frame.add(sa);
frame.setVisible(true);
sa.start();
}
public void init() {
// 指定目前图像为第一张图像
currentImage = 0;
// 使用八张动画图像
Animation = new Image[7];
MT = new MediaTracker(this);
// *注意此循环中的程序代码*
for (int i = 0; i < 7; i++) {
Animation[i] = this.getToolkit().getImage("Image/lanji"+i+ ".png");
MT.addImage(Animation[i], 0);
}
try {
// 在状态栏显示信息
// showStatus("图像加载中...");
// 等待所有图像下载
MT.waitForAll();
// 若捕捉到异常
} catch (InterruptedException e) {
// 建立错误页面的URL
// try {
// ErrorHTML = new URL(getCodeBase().toString() + "ErrorHTML.html");
// } catch (MalformedURLException e1) {
// }
// // 转移页面
// getAppletContext().showDocument(ErrorHTML);
}
}
// start()函数
public void start() {
newThread = new Thread(this);
newThread.start();
}
// stop()函数
public void stop() {
// 将线程设为null
newThread = null;
}
public void paint(Graphics g) {
// 绘制目前图像
g.drawImage(Animation[currentImage], 50, 10, 250, 250, this);
g.drawString("123456"+"\t"+currentImage, 20, 20);
}
public void run() {
while (newThread != null) {
// 重绘图像
repaint();
try {
// 暂停程序执行125毫秒
Thread.sleep(125);
} catch (InterruptedException e) {
// 建立错误页面的URL
// try {
// ErrorHTML = new URL(getCodeBase().toString()
// + "ErrorHTML.html");
// } catch (MalformedURLException e1) {
// }
// // 转移
// getAppletContext().showDocument(ErrorHTML);
}
// 如果已播放到最后一张图像
if (currentImage == 6)
// 指定目前图像为第一张图像
currentImage = 0;
else
// 指定图像为下一张图像
currentImage = currentImage + 1;
}
}
}
觉得我的回答不错就采纳吧,谢谢了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询