
下面是一个java 小程序实现的\x0d\import javaawt;//引入包\x0d\import javaappletApplet;//引入包\x0d\public class Output extends Applet//定义类\x0d\{\x0d\ //定义变量\x0d\ private String name;\x0d\ private int num;\x0d\ //初始化\x0d\ public void init()\x0d\ {\x0d\ name = getParameter("vname");\x0d\ num = IntegerparseInt(getParameter("vnum"));\x0d\ }\x0d\ //输出\x0d\ public void paint(Graphics g)\x0d\ {\x0d\ gdrawString ("姓名:"+name+";学号:"+num,20,30);\x0d\ }\x0d\}\x0d\\x0d\相应的html文件\x0d\\x0d\\x0d\\x0d\\x0d\\x0d\
汗
paint方法 在Component里头就定义了
也就是说
你程序中 重写的 paint方法 是JFrame从Component继承的
而不是你的Canvas中的paint方法 虽然名字一样
但是不同的类中 作用却不一样
你可以继承Canvas 然后重写paint方法 那就不一样了
package netmiqianggui;
import javaawtBasicStroke;
import javaawtBorderLayout;
import javaawtButton;
import javaawtColor;
import javaawtCursor;
import javaawtDimension;
import javaawtFrame;
import javaawtGraphics;
import javaawtGraphics2D;
import javaawtGridLayout;
import javaawtLabel;
import javaawtPanel;
import javaawtRenderingHints;
import javaawtToolkit;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventMouseAdapter;
import javaawteventMouseEvent;
import javaawteventMouseListener;
import javaawteventMouseMotionListener;
import javaawteventWindowAdapter;
import javaawteventWindowEvent;
import javaawtimageBufferedImage;
/
简单画图板程序
好久没用 AWT 了,写起来真别扭,如果用 swing 会很舒服,有空再改写吧。
@author 米强
/
public class TestMain extends Frame {
// 画板
private Palette palette = null;
// 显示当前颜色的面板
private Panel nonceColor = null;
// 画笔粗细
private Label drawWidth = null;
// 画笔端点的装饰
private Label drawCap = null;
// 选取颜色按钮的监听事件类
private ButtonColorAction buttonColorAction = null;
// 鼠标进入按钮后光标样式的监听事件类
private ButtonCursor buttonCursor = null;
// 画笔样式的监听事件
private ButtonStrokeAction buttonStrokeAction = null;
/
构造方法
/
public TestMain() {
// 设置标题栏文字
super("简易画图板");
// 构造一个画图板
palette = new Palette();
Panel pane = new Panel(new GridLayout(2, 1));
// 画笔颜色选择器
Panel paneColor = new Panel(new GridLayout(1, 13));
// 12 个颜色选择按钮
Button [] buttonColor = new Button[12];
Color [] color = {Colorblack, Colorblue, Colorcyan, ColordarkGray, Colorgray, Colorgreen, Colormagenta, Colororange, Colorpink, Colorred, Colorwhite, Coloryellow};
// 显示当前颜色的面板
nonceColor = new Panel();
nonceColorsetBackground(Colorblack);
paneColoradd(nonceColor);
buttonColorAction = new ButtonColorAction();
buttonCursor = new ButtonCursor();
for(int i = 0; i < buttonColorlength; i++){
buttonColor[i] = new Button();
buttonColor[i]setBackground(color[i]);
buttonColor[i]addActionListener(buttonColorAction);
buttonColor[i]addMouseListener(buttonCursor);
paneColoradd(buttonColor[i]);
}
paneadd(paneColor);
// 画笔颜色选择器
Panel paneStroke = new Panel(new GridLayout(1, 13));
// 控制画笔样式
buttonStrokeAction = new ButtonStrokeAction();
Button [] buttonStroke = new Button[11];
buttonStroke[0] = new Button("1");
buttonStroke[1] = new Button("3");
buttonStroke[2] = new Button("5");
buttonStroke[3] = new Button("7");
buttonStroke[4] = new Button("9");
buttonStroke[5] = new Button("11");
buttonStroke[6] = new Button("13");
buttonStroke[7] = new Button("15");
buttonStroke[8] = new Button("17");
buttonStroke[9] = new Button("■");
buttonStroke[10] = new Button("●");
drawWidth = new Label("3", LabelCENTER);
drawCap = new Label("●", LabelCENTER);
drawWidthsetBackground(ColorlightGray);
drawCapsetBackground(ColorlightGray);
paneStrokeadd(drawWidth);
for(int i = 0; i < buttonStrokelength; i++){
paneStrokeadd(buttonStroke[i]);
buttonStroke[i]addMouseListener(buttonCursor);
buttonStroke[i]addActionListener(buttonStrokeAction);
if(i <= 8){
buttonStroke[i]setName("width");
}else{
buttonStroke[i]setName("cap");
}
if(i == 8){
paneStrokeadd(drawCap);
}
}
paneadd(paneStroke);
// 将画笔颜色选择器添加到窗体中
thisadd(pane, BorderLayoutNORTH);
// 将画图板添加到窗体中
thisadd(palette);
// 添加窗口监听,点击关闭按钮时退出程序
thisaddWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Systemexit(0);
}
});
// 设置窗体 ICON 图标
thissetIconImage(ToolkitgetDefaultToolkit()createImage("images/palettepng"));
// 设置窗口的大小
thissetSize(new Dimension(400, 430));
// 设置窗口位置,处于屏幕正中央
thissetLocationRelativeTo(null);
// 显示窗口
thissetVisible(true);
}
/
程序入口
@param args
字符串数组参数
/
public static void main(String[] args) {
new TestMain();
}
/
选取颜色按钮的监听事件类
@author 米强
/
class ButtonColorAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
Color color_temp = ((Button)egetSource())getBackground();
nonceColorsetBackground(color_temp);
palettesetColor(color_temp);
}
}
/
鼠标进入按钮变换光标样式监听事件类
@author 米强
/
class ButtonCursor extends MouseAdapter {
public void mouseEntered(MouseEvent e) {
((Button)egetSource())setCursor(new Cursor(CursorHAND_CURSOR));
}
public void mouseExited(MouseEvent e) {
((Button)egetSource())setCursor(new Cursor(CursorDEFAULT_CURSOR));
}
}
/
设置画笔的监听事件类
@author 米强
/
class ButtonStrokeAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
Button button_temp = (Button) egetSource();
String name = button_tempgetName();
if(nameequalsIgnoreCase("width")){
drawWidthsetText(button_tempgetLabel());
palettesetStroke(FloatparseFloat(button_tempgetLabel()));
}else if(nameequalsIgnoreCase("cap")){
drawCapsetText(button_tempgetLabel());
if(button_tempgetLabel()equals("■")){
palettesetStroke(BasicStrokeCAP_SQUARE);
}else if(button_tempgetLabel()equals("●")){
palettesetStroke(BasicStrokeCAP_ROUND);
}
}
}
}
}
/
画板类
@author 米强
/
class Palette extends Panel implements MouseListener, MouseMotionListener {
// 鼠标 X 坐标的位置
private int mouseX = 0;
// 上一次 X 坐标位置
private int oldMouseX = 0;
// 鼠标 Y 坐标的位置
private int mouseY = 0;
// 上一次 Y 坐标位置
private int oldMouseY = 0;
// 画图颜色
private Color color = null;
// 画笔样式
private BasicStroke stroke = null;
// 缓存图形
private BufferedImage image = null;
/
构造一个画板类
/
public Palette() {
thisaddMouseListener(this);
thisaddMouseMotionListener(this);
// 默认黑色画笔
color = new Color(0, 0, 0);
// 设置默认画笔样式
stroke = new BasicStroke(30f, BasicStrokeCAP_ROUND, BasicStrokeJOIN_ROUND);
// 建立 1280 1024 的 RGB 缓存图象
image = new BufferedImage(1280, 1024, BufferedImageTYPE_INT_RGB);
// 设置颜色
imagegetGraphics()setColor(Colorwhite);
// 画背景
imagegetGraphics()fillRect(0, 0, 1280, 1024);
}
/
重写 paint 绘图方法
/
public void paint(Graphics g) {
superpaint(g);
// 转换为 Graphics2D
Graphics2D g2d = (Graphics2D) g;
// 获取缓存图形 Graphics2D
Graphics2D bg = imagecreateGraphics();
// 图形抗锯齿
bgsetRenderingHint(RenderingHintsKEY_ANTIALIASING, RenderingHintsVALUE_ANTIALIAS_ON);
// 设置绘图颜色
bgsetColor(color);
// 设置画笔样式
bgsetStroke(stroke);
// 画线,从上一个点到新的点
bgdrawLine(oldMouseX, oldMouseY, mouseX, mouseY);
// 将缓存中的图形画到画板上
g2ddrawImage(image, 0, 0, this);
}
/
重写 update 方法
/
public void update(Graphics g) {
thispaint(g);
}
/
@return stroke
/
public BasicStroke getStroke() {
return stroke;
}
/
@param stroke 要设置的 stroke
/
public void setStroke(BasicStroke stroke) {
thisstroke = stroke;
}
/
设置画笔粗细
@param width
/
public void setStroke(float width) {
thisstroke = new BasicStroke(width, strokegetEndCap(), strokegetLineJoin());
}
/
设置画笔端点的装饰
@param cap 参考 javaawtBasicStroke 类静态字段
/
public void setStroke(int cap) {
thisstroke = new BasicStroke(strokegetLineWidth(), cap, strokegetLineJoin());
}
/
@return color
/
public Color getColor() {
return color;
}
/
@param color 要设置的 color
/
public void setColor(Color color) {
thiscolor = color;
}
public void mouseClicked(MouseEvent mouseEvent) {
}
/
鼠标按下
/
public void mousePressed(MouseEvent mouseEvent) {
thisoldMouseX = thismouseX = mouseEventgetX();
thisoldMouseY = thismouseY = mouseEventgetY();
repaint();
}
public void mouseReleased(MouseEvent mouseEvent) {
}
/
鼠标进入棋盘
/
public void mouseEntered(MouseEvent mouseEvent) {
thissetCursor(new Cursor(CursorCROSSHAIR_CURSOR));
}
/
鼠标退出棋盘
/
public void mouseExited(MouseEvent mouseEvent) {
thissetCursor(new Cursor(CursorDEFAULT_CURSOR));
}
/
鼠标拖动
/
public void mouseDragged(MouseEvent mouseEvent) {
thisoldMouseX = thismouseX;
thisoldMouseY = thismouseY;
thismouseX = mouseEventgetX();
thismouseY = mouseEventgetY();
repaint();
}
public void mouseMoved(MouseEvent mouseEvent) {
}
}
粗略地做了一个出来,闪烁的问题暂时无法解决,其他的还可以吧,先上代码:
import javaawtGraphics;import javaawtImage;
import javaawteventMouseEvent;
import javaawteventMouseListener;
import javaawteventMouseMotionListener;
import javaioIOException;
import javautilArrayList;
import javautilList;
import javaximageioImageIO;
import javaxswingJFrame;
public class TestImage extends JFrame implements MouseListener, MouseMotionListener {
private Image offScreenImage;
private Image background, sprite;
private static final int WIDTH = 800;
private static final int HEIGHT = 600;
private int x0 = 0, y0 = 0;
private int x1, y1;
private List<Bounds> bounds;
private Bounds mCurrentBounds = null;
public TestImage() {
super("绘图");
bounds = new ArrayList<Bounds>();
}
private void launch() {
setSize(WIDTH, HEIGHT);
setResizable(false);
setVisible(true);
try {
background = ImageIOread(TestImageclassgetResource("/res/clockjpg"));
sprite = ImageIOread(TestImageclassgetResource("/res/light_buble2png"));
} catch (IOException e) {
eprintStackTrace();
}
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
new Thread(new Repaint())start();
addMouseListener(this);
addMouseMotionListener(this);
}
@Override
public void update(Graphics g) {
if(null == offScreenImage) {
offScreenImage = createImage(WIDTH, HEIGHT);
}
Graphics gImage = offScreenImagegetGraphics();
gImageclearRect(0, 0, WIDTH, HEIGHT);
paint(gImage);
gdrawImage(offScreenImage, 0, 0, null);
}
@Override
public void paint(Graphics g) {
gdrawImage(background, 0, 0, WIDTH, HEIGHT, null);
for(Bounds bound : bounds) {
gdrawImage(sprite, boundx0, boundy0, boundx1 - boundx0, boundy1 - boundy0, null);
}
if(null != mCurrentBounds) {
gdrawImage(sprite, mCurrentBoundsx0, mCurrentBoundsy0,
Mathabs(mCurrentBoundsx1 - mCurrentBoundsx0),
Mathabs(mCurrentBoundsy1 - mCurrentBoundsy0), null);
}
}
public static void main(String[] args) {
new TestImage()launch();
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
x1 = x0 = egetX();
y1 = y0 = egetY();
mCurrentBounds = new Bounds(x0, y0, x1, y1);
}
@Override
public void mouseReleased(MouseEvent e) {
if(null != mCurrentBounds) {
boundsadd(mCurrentBounds);
}
mCurrentBounds = null;
}
@Override
public void mouseDragged(MouseEvent e) {
if(null != mCurrentBounds) {
int x = egetX();
int y = egetY();
if(x > x0) {
x1 = x;
} else {
x0 = x;
}
if(y > y0) {
y1 = y;
} else {
y0 = y;
}
mCurrentBoundssetBounds(x0, x1, y0, y1);
}
}
@Override
public void mouseMoved(MouseEvent e) {
}
class Repaint implements Runnable {
@Override
public void run() {
while(true) {
try {
Threadsleep(30L);
repaint();
} catch (InterruptedException e) {
eprintStackTrace();
}
}
}
}
}
class Bounds {
public int x0;
public int y0;
public int x1;
public int y1;
public Bounds(int x0, int y0, int x1, int y1) {
thisx0 = x0;
thisy0 = y0;
thisx1 = x1;
thisy1 = y1;
}
public void setBounds(int x0, int x1, int y0, int y1) {
thisx0 = x0;
thisx1 = x1;
thisy0 = y0;
thisy1 = y1;
}
}
运行时就是鼠标点击画板并按住,然后拖拽就可以画一个电灯出来。所需的资源在附件内,根据代码相信你应该能够知道要放到哪个目录下吧。运行效果也截一个图给你。
class Triangle extends drawings//空心三角形类
{
void draw(Graphics2D g2d)
{g2dsetPaint(new Color(R,G,B));
g2dsetStroke(new BasicStroke(stroke,
BasicStrokeCAP_ROUND,BasicStrokeJOIN_BEVEL));
g2ddrawLine((int)((x1+x2)/2),Mathmin(y1,y2),Mathmax(x1,x2),Mathmax(y1,y2));
g2ddrawLine(Mathmax(x1,x2),Mathmax(y1,y2),Mathmin(x1,x2),Mathmax(y1,y2));
g2ddrawLine(Mathmin(x1,x2),Mathmax(y1,y2),(int)((x1+x2)/2),Mathmin(y1,y2));
}
}
以上是通过绘制三条直线作为三角形的三条边来绘制三角形
class fillTriangle extends drawings//实心三角形
{
void draw(Graphics2D g2d)
{g2dsetPaint(new Color(R,G,B));
g2dsetStroke(new BasicStroke(stroke));
int mx=(int)((x1+x2)/2);
int[] x={mx,Mathmax(x1,x2),Mathmin(x1,x2)};
int[] y={Mathmin(y1,y2),Mathmax(y1,y2),Mathmax(y1,y2)};
g2dfillPolygon(x,y,3);
}
}
以上是用填充多边形的方式填充一个三角形,如果把最后的:g2dfillPolygon(x,y,3)改为g2ddrawPolygon(x,y,3); 则是以绘制多边形的方式绘制空心三角形
这里说明一下:因为(x1,y1,x2,y2)只能确定一个矩形区域,即鼠标拉动的起点和终点确定的矩形区域所以可以有多种方式确定三角形的三个顶点,我这个用的三个顶点是:
点1( (x1+x2)/2, min(y) ) 点2( max(x),max(y) ) 点3( min(x),max(y) )
你的补充内容太多了,没心情看啊,太累了
我有一个程序,一次过满足了你第一、第二个要求。你百度HI联系我,我发代码给你。现在就有。
这里先贴上计算器的代码:
package MyProject;
import javaawt;
import javaawtevent;
import javalang;
import javaxswing;
public class Counter extends Frame
{
//声明三个面板的布局
GridLayout gl1,gl2,gl3;
Panel p0,p1,p2,p3;
JTextField tf1;
TextField tf2;
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26;
StringBuffer str;//显示屏所显示的字符串
double x,y;//x和y都是运算数
int z;//Z表示单击了那一个运算符0表示"+",1表示"-",2表示"",3表示"/"
static double m;//记忆的数字
public Counter()
{
gl1=new GridLayout(1,4,10,0);//实例化三个面板的布局
gl2=new GridLayout(4,1,0,15);
gl3=new GridLayout(4,5,10,15);
tf1=new JTextField(27);//显示屏
tf1setHorizontalAlignment(JTextFieldRIGHT);
tf1setEnabled(false);
tf1setText("0");
tf2=new TextField(10);//显示记忆的索引值
tf2setEditable(false);
//实例化所有按钮、设置其前景色并注册监听器
b0=new Button("Backspace");
b0setForeground(Colorred);
b0addActionListener(new Bt());
b1=new Button("CE");
b1setForeground(Colorred);
b1addActionListener(new Bt());
b2=new Button("C");
b2setForeground(Colorred);
b2addActionListener(new Bt());
b3=new Button("MC");
b3setForeground(Colorred);
b3addActionListener(new Bt());
b4=new Button("MR");
b4setForeground(Colorred);
b4addActionListener(new Bt());
b5=new Button("MS");
b5setForeground(Colorred);
b5addActionListener(new Bt());
b6=new Button("M+");
b6setForeground(Colorred);
b6addActionListener(new Bt());
b7=new Button("7");
b7setForeground(Colorblue);
b7addActionListener(new Bt());
b8=new Button("8");
b8setForeground(Colorblue);
b8addActionListener(new Bt());
b9=new Button("9");
b9setForeground(Colorblue);
b9addActionListener(new Bt());
b10=new Button("/");
b10setForeground(Colorred);
b10addActionListener(new Bt());
b11=new Button("sqrt");
b11setForeground(Colorblue);
b11addActionListener(new Bt());
b12=new Button("4");
b12setForeground(Colorblue);
b12addActionListener(new Bt());
b13=new Button("5");
b13setForeground(Colorblue);
b13addActionListener(new Bt());
b14=new Button("6");
b14setForeground(Colorblue);
b14addActionListener(new Bt());
b15=new Button("");
b15setForeground(Colorred);
b15addActionListener(new Bt());
b16=new Button("%");
b16setForeground(Colorblue);
b16addActionListener(new Bt());
b17=new Button("1");
b17setForeground(Colorblue);
b17addActionListener(new Bt());
b18=new Button("2");
b18setForeground(Colorblue);
b18addActionListener(new Bt());
b19=new Button("3");
b19setForeground(Colorblue);
b19addActionListener(new Bt());
b20=new Button("-");
b20setForeground(Colorred);
b20addActionListener(new Bt());
b21=new Button("1/X");
b21setForeground(Colorblue);
b21addActionListener(new Bt());
b22=new Button("0");
b22setForeground(Colorblue);
b22addActionListener(new Bt());
b23=new Button("+/-");
b23setForeground(Colorblue);
b23addActionListener(new Bt());
b24=new Button("");
b24setForeground(Colorblue);
b24addActionListener(new Bt());
b25=new Button("+");
b25setForeground(Colorred);
b25addActionListener(new Bt());
b26=new Button("=");
b26setForeground(Colorred);
b26addActionListener(new Bt());
//实例化四个面板
p0=new Panel();
p1=new Panel();
p2=new Panel();
p3=new Panel();
//创建一个空字符串缓冲区
str=new StringBuffer();
//添加面板p0中的组件和设置其在框架中的位置和大小
p0add(tf1);
p0setBounds(10,25,300,40);
//添加面板p1中的组件和设置其在框架中的位置和大小
p1setLayout(gl1);
p1add(tf2);
p1add(b0);
p1add(b1);
p1add(b2);
p1setBounds(10,65,300,25);
//添加面板p2中的组件并设置其的框架中的位置和大小
p2setLayout(gl2);
p2add(b3);
p2add(b4);
p2add(b5);
p2add(b6);
p2setBounds(10,110,40,150);
//添加面板p3中的组件并设置其在框架中的位置和大小
p3setLayout(gl3);//设置p3的布局
p3add(b7);
p3add(b8);
p3add(b9);
p3add(b10);
p3add(b11);
p3add(b12);
p3add(b13);
p3add(b14);
p3add(b15);
p3add(b16);
p3add(b17);
p3add(b18);
p3add(b19);
p3add(b20);
p3add(b21);
p3add(b22);
p3add(b23);
p3add(b24);
p3add(b25);
p3add(b26);
p3setBounds(60,110,250,150);
//设置框架中的布局为空布局并添加4个面板
setLayout(null);
add(p0);
add(p1);
add(p2);
add(p3);
setResizable(false);//禁止调整框架的大小
//匿名类关闭窗口
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e1)
{
MainFramegetMyMainFrame()setEnabled(true);
Counterthisdispose();
}
});
setBackground(ColorlightGray);
setBounds(100,100,320,280);
setVisible(true);
}
//构造监听器
class Bt implements ActionListener
{
public void actionPerformed(ActionEvent e2)
{
try{
if(e2getSource()==b1)//选择"CE"清零
{
tf1setText("0");//把显示屏清零
strsetLength(0);//清空字符串缓冲区以准备接收新的输入运算数
}
else if(e2getSource()==b2)//选择"C"清零
{
tf1setText("0");//把显示屏清零
strsetLength(0);
}
else if(e2getSource()==b23)//单击"+/-"选择输入的运算数是正数还是负数
{
x=DoubleparseDouble(tf1getText()trim());
tf1setText(""+(-x));
}
else if(e2getSource()==b25)//单击加号按钮获得x的值和z的值并清空y的值
{
x=DoubleparseDouble(tf1getText()trim());
strsetLength(0);//清空缓冲区以便接收新的另一个运算数
y=0d;
z=0;
}
else if(e2getSource()==b20)//单击减号按钮获得x的值和z的值并清空y的值
{
x=DoubleparseDouble(tf1getText()trim());
strsetLength(0);
y=0d;
z=1;
}
else if(e2getSource()==b15)//单击乘号按钮获得x的值和z的值并清空y的值
{
x=DoubleparseDouble(tf1getText()trim());
strsetLength(0);
y=0d;
z=2;
}
else if(e2getSource()==b10)//单击除号按钮获得x的值和z的值并空y的值
{
x=DoubleparseDouble(tf1getText()trim());
strsetLength(0);
y=0d;
z=3;
}
else if(e2getSource()==b26)//单击等号按钮输出计算结果
{
strsetLength(0);
switch(z)
{
case 0 : tf1setText(""+(x+y));break;
case 1 : tf1setText(""+(x-y));break;
case 2 : tf1setText(""+(xy));break;
case 3 : tf1setText(""+(x/y));break;
}
}
else if(e2getSource()==b24)//单击""按钮输入小数
{
if(tf1getText()trim()indexOf("")!=-1)//判断字符串中是否已经包含了小数点
{
}
else//如果没数点有小
{
if(tf1getText()trim()equals("0"))//如果初时显示为0
{
strsetLength(0);
tf1setText((strappend("0"+e2getActionCommand()))toString());
}
else if(tf1getText()trim()equals(""))//如果初时显示为空则不做任何 *** 作
{
}
else
{
tf1setText(strappend(e2getActionCommand())toString());
}
}
y=0d;
}
else if(e2getSource()==b11)//求平方根
{
x=DoubleparseDouble(tf1getText()trim());
tf1setText("数字格式异常");
if(x<0)
tf1setText("负数没有平方根");
else
tf1setText(""+Mathsqrt(x));
strsetLength(0);
y=0d;
}
else if(e2getSource()==b16)//单击了"%"按钮
{
x=DoubleparseDouble(tf1getText()trim());
tf1setText(""+(001x));
strsetLength(0);
y=0d;
}
else if(e2getSource()==b21)//单击了"1/X"按钮
{
x=DoubleparseDouble(tf1getText()trim());
if(x==0)
{
tf1setText("除数不能为零");
}
else
{
tf1setText(""+(1/x));
}
strsetLength(0);
y=0d;
}
else if(e2getSource()==b3)//MC为清除内存
{
m=0d;
tf2setText("");
strsetLength(0);
}
else if(e2getSource()==b4)//MR为重新调用存储的数据
{
if(tf2getText()trim()!="")//有记忆数字
{
tf1setText(""+m);
}
}
else if(e2getSource()==b5)//MS为存储显示的数据
{
m=DoubleparseDouble(tf1getText()trim());
tf2setText("M");
tf1setText("0");
strsetLength(0);
}
else if(e2getSource()==b6)//M+为将显示的数字与已经存储的数据相加要查看新的数字单击MR
{
m=m+DoubleparseDouble(tf1getText()trim());
}
else//选择的是其他的按钮
{
if(e2getSource()==b22)//如果选择的是"0"这个数字键
{
if(tf1getText()trim()equals("0"))//如果显示屏显示的为零不做 *** 作
{
}
else
{
tf1setText(strappend(e2getActionCommand())toString());
y=DoubleparseDouble(tf1getText()trim());
}
}
else if(e2getSource()==b0)//选择的是“BackSpace”按钮
{
if(!tf1getText()trim()equals("0"))//如果显示屏显示的不是零
{
if(strlength()!=1)
{
tf1setText(strdelete(strlength()-1,strlength())toString());//可能抛出字符串越界异常
}
else
{
tf1setText("0");
strsetLength(0);
}
}
y=DoubleparseDouble(tf1getText()trim());
}
else//其他的数字键
{
tf1setText(strappend(e2getActionCommand())toString());
y=DoubleparseDouble(tf1getText()trim());
}
}
}
catch(NumberFormatException e){
tf1setText("数字格式异常");
}
catch(StringIndexOutOfBoundsException e){
tf1setText("字符串索引越界");
}
}
}
public static void main(String args[])
{
new Counter();
}
}
以上就是关于怎么编写一个简单Java应用程序,输出自己的姓名和学号全部的内容,包括:怎么编写一个简单Java应用程序,输出自己的姓名和学号、java绘图、求java图形编译程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)