当前位置: 技术问答>java相关
如何用java实现:与后台数据库相连生成曲线图
来源: 互联网 发布时间:2015-01-02
本文导语: 请java高手指教... | import java.awt.*; import java.util.*; import java.applet.Applet; public class SimplePlot extends Applet { TextField fromFld, toFld; String MyText; Label label, toLabel, fromLabel, statusLabel; P...
请java高手指教...
|
import java.awt.*;
import java.util.*;
import java.applet.Applet;
public class SimplePlot extends Applet {
TextField fromFld, toFld;
String MyText;
Label label, toLabel, fromLabel, statusLabel;
PlotCanvas canvas;
public int i;
Button redb, blueb, domainChangeb;
Color color;
Panel panel1, panel2, bottomPanel, statusPanel, xdomainPanel;
Choice fnChoice;
float beginXmin = -100, beginXmax = 100;
public void init() {
setLayout(new BorderLayout(5,5));
panel1 = new Panel();
label = new Label("Plotting a Function");
panel1.add(label);
add("North", panel1);
panel2 = new Panel();
panel2.setLayout(new GridLayout(0,1,5,5));
panel2.add(new Label("Choose a Color"));
redb = new Button("RED");
redb.setBackground(Color.red);
panel2.add(redb);
blueb = new Button("BLUE");
blueb.setBackground(Color.blue);
panel2.add(blueb);
panel2.add(new Label("Choose a Function"));
fnChoice = new Choice();
fnChoice.addItem("x^2");
fnChoice.addItem("x + 30");
fnChoice.addItem("x^3");
fnChoice.addItem("x^2 + x - 52");
panel2.add(fnChoice);
add("East", panel2);
canvas = new PlotCanvas(this);
add("Center", canvas);
fromLabel = new Label("-100");
/* Bottom Panel, with from and to and status line. */
bottomPanel = new Panel();
bottomPanel.setLayout(new GridLayout(0,1,5,5));
/* Domain panel */
xdomainPanel = new Panel();
xdomainPanel.add(new Label("Plot x from : "));
fromFld = new TextField("-100", 7);
canvas.setXmin(-100);
xdomainPanel.add(fromFld);
xdomainPanel.add(new Label("to : "));
toFld = new TextField("100", 10);
canvas.setXmax(100);
xdomainPanel.add(toFld);
domainChangeb = new Button ("Change Domain");
xdomainPanel.add(domainChangeb);
bottomPanel.add(xdomainPanel);
/* Status Line */
statusPanel = new Panel();
statusLabel = new Label(" ");
statusLabel.setForeground(Color.magenta);
statusPanel.add(statusLabel);
bottomPanel.add(statusPanel);
add("South", bottomPanel);
}
/** Draws a box around this panel. */
public void paint(Graphics g) {
Dimension d = size();
g.drawRect(0,0, d.width - 1, d.height - 1);
}
public Insets insets() {
return new Insets(5,5,5,8);
}
public boolean handleEvent(Event e) {
int newFn;
try {
if ((e.target instanceof Button)
&& (e.id == Event.ACTION_EVENT)) {
if (e.target == redb) {
canvas.changeColor(Color.red);
}
else if (e.target == blueb) {
canvas.changeColor(Color.blue);
}
else if (e.target == domainChangeb) {
float newXmin = 0, newXmax = 0;
/* Do this to get rid of a possible
"Domain must be a number" message */
statusLabel.setText(" ");
newXmin = Float.valueOf(fromFld.getText()).floatValue();
newXmax = Float.valueOf(toFld.getText()).floatValue();
if (newXmax
import java.util.*;
import java.applet.Applet;
public class SimplePlot extends Applet {
TextField fromFld, toFld;
String MyText;
Label label, toLabel, fromLabel, statusLabel;
PlotCanvas canvas;
public int i;
Button redb, blueb, domainChangeb;
Color color;
Panel panel1, panel2, bottomPanel, statusPanel, xdomainPanel;
Choice fnChoice;
float beginXmin = -100, beginXmax = 100;
public void init() {
setLayout(new BorderLayout(5,5));
panel1 = new Panel();
label = new Label("Plotting a Function");
panel1.add(label);
add("North", panel1);
panel2 = new Panel();
panel2.setLayout(new GridLayout(0,1,5,5));
panel2.add(new Label("Choose a Color"));
redb = new Button("RED");
redb.setBackground(Color.red);
panel2.add(redb);
blueb = new Button("BLUE");
blueb.setBackground(Color.blue);
panel2.add(blueb);
panel2.add(new Label("Choose a Function"));
fnChoice = new Choice();
fnChoice.addItem("x^2");
fnChoice.addItem("x + 30");
fnChoice.addItem("x^3");
fnChoice.addItem("x^2 + x - 52");
panel2.add(fnChoice);
add("East", panel2);
canvas = new PlotCanvas(this);
add("Center", canvas);
fromLabel = new Label("-100");
/* Bottom Panel, with from and to and status line. */
bottomPanel = new Panel();
bottomPanel.setLayout(new GridLayout(0,1,5,5));
/* Domain panel */
xdomainPanel = new Panel();
xdomainPanel.add(new Label("Plot x from : "));
fromFld = new TextField("-100", 7);
canvas.setXmin(-100);
xdomainPanel.add(fromFld);
xdomainPanel.add(new Label("to : "));
toFld = new TextField("100", 10);
canvas.setXmax(100);
xdomainPanel.add(toFld);
domainChangeb = new Button ("Change Domain");
xdomainPanel.add(domainChangeb);
bottomPanel.add(xdomainPanel);
/* Status Line */
statusPanel = new Panel();
statusLabel = new Label(" ");
statusLabel.setForeground(Color.magenta);
statusPanel.add(statusLabel);
bottomPanel.add(statusPanel);
add("South", bottomPanel);
}
/** Draws a box around this panel. */
public void paint(Graphics g) {
Dimension d = size();
g.drawRect(0,0, d.width - 1, d.height - 1);
}
public Insets insets() {
return new Insets(5,5,5,8);
}
public boolean handleEvent(Event e) {
int newFn;
try {
if ((e.target instanceof Button)
&& (e.id == Event.ACTION_EVENT)) {
if (e.target == redb) {
canvas.changeColor(Color.red);
}
else if (e.target == blueb) {
canvas.changeColor(Color.blue);
}
else if (e.target == domainChangeb) {
float newXmin = 0, newXmax = 0;
/* Do this to get rid of a possible
"Domain must be a number" message */
statusLabel.setText(" ");
newXmin = Float.valueOf(fromFld.getText()).floatValue();
newXmax = Float.valueOf(toFld.getText()).floatValue();
if (newXmax