java简易画图程序代码 java绘制图形代码( 六 )


displayField.setText(displayField.getText()+input);
}
}
else if (e.getActionCommand()=="二进制")//二进制的转换
{
int n=Integer.parseInt(displayField.getText());
displayField.setText(Integer.toBinaryString(n));
}
else if (e.getActionCommand()=="八进制")//八进制的转换
{
int n=Integer.parseInt(displayField.getText());
displayField.setText(Integer.toOctalString(n));
}
else if (e.getActionCommand()=="退出")//选项中退出的处理方法
{
System.exit(0);
}
else if (e.getActionCommand()=="用法")//按下'帮助'菜单栏中用法的处理方法
{
label_dialog.setText("sqrt,exp等键是先输运算符再输数字\n");
dialog.setLocation(400,250);
dialog.setVisible(true);
}
else//各运算符的识别
{
String command=e.getActionCommand();
if(start)
{
lastCommand=command;
}
else
{
calculate(Double.parseDouble(displayField.getText()));
lastCommand=command;
start=true;
}
}
}
public void calculate(double x)//各运算符的具体运算方法
{
double d=0;
if (lastCommand.equals("+"))
result+= x;
else if (lastCommand.equals("-"))
result-=x;
else if (lastCommand.equals("*"))
result*=x;
else if (lastCommand.equals("/"))
result/=x;
else if (lastCommand.equals("="))
result=x;
else if (lastCommand.equals("sqrt"))
{
d=Math.sqrt(x);
result=d;
}
else if (lastCommand.equals("exp"))
{
d=Math.exp(x);
result=d;
}
else if (lastCommand.equals("log"))
{
d=Math.log(x);
result=d;
}
else if (lastCommand.equals("tan"))
{
d=Math.tan(x);
result=d;
}
else if (lastCommand.equals("cos"))
{
d=Math.cos(x);
result=d;
}
else if (lastCommand.equals("sin"))
{
d=Math.sin(x);
result=d;
}
displayField.setText(""+ result);
}
public void windowClosing(WindowEvent e)
{
if(e.getSource()==dialog)
dialog.setVisible(false);//隐藏对话框
else
System.exit(0);
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public static void main(String args[])
{
Calculator calculator=new Calculator();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)//单击窗口关闭按钮时触发并执行实现窗口监听器接口中的方法
{
System.exit(0);//结束程序运行
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}
求一个java程序:绘图程序包括画圆,椭圆,线 , 矩形,自定义 。并且可以调图形颜色!public enum ShapeTypes {
LINE, CIRCLE, RECTANGLE
}
public interface Shape {
void paint(Graphics g);
}
public class Rectangle implements Shape {
// 矩形左上角java简易画图程序代码的坐标
private int x, y;
// 矩形java简易画图程序代码的宽度和高度
private int width, height;
private Color rectangleColor;
public Rectangle() {
super();
}
public Rectangle(int x, int y, int width, int height, Color rectangleColor) {

推荐阅读