showweight.java
来自「Usefull sample codes for Java. Containt 」· Java 代码 · 共 34 行
JAVA
34 行
import java.awt.*;
public class ShowWeight extends javax.swing.JApplet {
float lbs = (float)0;
float ozs;
float kgs;
float metricTons;
String name = "somebody";
public void init() {
String lbsValue = getParameter("weight");
if (lbsValue != null) {
Float lbsTemp = Float.valueOf(lbsValue);
lbs = lbsTemp.floatValue();
}
String personValue = getParameter("person");
if (personValue != null) {
name = personValue;
}
ozs = (float)(lbs * 16);
kgs = (float)(lbs / 2.204623);
metricTons = (float)(lbs / 2204.623);
}
public void paint(Graphics screen) {
Graphics2D screen2D = (Graphics2D) screen;
screen2D.drawString("Studying the weight of " + name, 5, 30);
screen2D.drawString("In pounds: " + lbs, 55, 50);
screen2D.drawString("In ounces: " + ozs, 55, 70);
screen2D.drawString("In kilograms: " + kgs, 55, 90);
screen2D.drawString("In metric tons: " + metricTons, 55, 110);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?