JComboBox cb;
JButton bn1 = new JButton("变宽"),
bn2 = new JButton("变窄"),
bn3 = new JButton("拉长"),
bn4 = new JButton("压短"),
bn = new JButton("绘图"),
exit = new JButton("退出"),
bn5 = new JButton("左移"),
bn6 = new JButton("右移"),
bn7 = new JButton("上移"),
bn8 = new JButton("下移");
public UI()
{
mp = new MyPanel(this);
pl1.setLayout(new GridLayout(1, 2));
pl2.setLayout(new GridLayout(1, 2));
pl3.setLayout(new GridLayout(1, 2));
pl4.setLayout(new GridLayout(1, 2));
pl1.add(bn1); bn1.setEnabled(false);
pl1.add(bn2); bn2.setEnabled(false);
pl2.add(bn3); bn3.setEnabled(false);
pl2.add(bn4); bn4.setEnabled(false);
pl3.add(bn5); bn5.setEnabled(false);
pl3.add(bn6); bn6.setEnabled(false);
pl4.add(bn7); bn7.setEnabled(false);
pl4.add(bn8); bn8.setEnabled(false);
pl.setLayout(new GridLayout(20, 1));
rb1 = new JRadioButton("输入函数");
rb2 = new JRadioButton("选择已有函数");
rb2.setSelected(true);
tf.setEnabled(false);
bg.add(rb1); bg.add(rb2);
rb1.addActionListener(mp);
rb2.addActionListener(mp);
pl.add(rb1);
pl.add(tf);
pl.add(rb2);
cb = new JComboBox(s);
pl.add(cb);
pl.add(new JLabel());
pl.add(pl1); pl.add(pl2);
pl.add(pl3); pl.add(pl4);
pl.add(bn);
pl.add(exit);
bn1.addActionListener(mp);
bn2.addActionListener(mp);
bn3.addActionListener(mp);
bn4.addActionListener(mp);
bn5.addActionListener(mp);
bn6.addActionListener(mp);
bn7.addActionListener(mp);
bn8.addActionListener(mp);
bn.addActionListener(mp);
exit.addActionListener(mp);
this.setLayout(new BorderLayout());
this.add(mp, BorderLayout.CENTER);
this.add(pl, BorderLayout.EAST);
this.setTitle("平面直角坐标系画图小工具");
this.setSize(797, 600 + 37);
Dimension dn = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((dn.width - 797) / 2, (dn.height - 637) / 2);
this.setVisible(true);
this.setDefaultCloseOperation(3);
}
public static void main(String[] args)
{
new UI();
}
}
package math;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class MyPanel extends JPanel implements ActionListener,MouseMotionListener
{
UI ui;
int flag;
double h_times;
int w_times;
int dx;
int dy;
String str;
Point pt = new Point(0, 0);
void init()
{
flag = -1;
h_times = Math.PI / 100;
w_times = 100;
dx = 300;
dy = 300;
}
public MyPanel(UI ui)
{
this.addMouseMotionListener(this);
init();
this.ui = ui;
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
drawCoordinate(g2);
Line2D line;
g2.setColor(Color.BLUE);
g2.drawString("(" + (pt.x - 300) + ", " + (300 - pt.y) + ")", pt.x + 20, pt.y + 20);
switch(flag)
{
case 0:
g2.drawString("y = Asin(Bx + C) + D", 105, 60);
for(double i = 0; i600; i += 0.01)
{
line = new Line2D.Double(i, dy - Math.sin(getReal_X(i)) * w_times, i + 1, dy - Math.sin(getReal_X(i + 1)) * w_times);
g2.draw(line);
}
break;
case 1:
g2.drawString("y = Acos(Bx + C) + D", 105, 60);
推荐阅读
- gis里如何画面,gis 画图形
- 解析js对象的属性,js修改对象的某个属性的值
- jqueryui中文api,jquery 中文网
- ps4恋爱养成游戏排行,ps4恋爱养成游戏排行榜在哪看
- 怎么关闭mysql的日志 mysql8关闭binlog
- 发舞狮视频配什么成语的简单介绍
- les与sap集成关键的简单介绍
- 制作饼干视频用什么面粉,做饼干用的什么面粉
- 水仙花python函数 python,水仙花数