public void paint(Graphics g) 不是为 double 绘制,而是为 string 绘制,我想将 string 转换为 double。
所以我试图做一个堆栈计算器,我使用链表来做它,把油漆的部分加倍没有做我想要的。我想要的是我有按钮来按住加法和除法等。我试图输入一个数字,它会立即在我的窗口上绘制它,但它没有这样做。我使用日食。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import NumberTree.Ornament;
import java.util.Iterator;
import java.util.LinkedList;
public class StackCalc extends JFrame implements ActionListener {
private LinkedList<Double> values;
double value1 , value2 ;
JTextField theTextField;
JButton boxButton;
public static void main ( String[] args) {
new StackCalc();
}
public StackCalc() {
setDefaultCloseOperation( EXIT_ON_CLOSE );
setLayout( new FlowLayout());
setTitle("StackCalc");
setSize(new Dimension(600,600));
boxButton = new JButton("add");
add(boxButton);
boxButton.addActionListener( this );
boxButton = new JButton("multi");
add(boxButton);
boxButton.addActionListener( this );
boxButton = new JButton("divide");
add(boxButton);
boxButton.addActionListener( this );
boxButton = new JButton("subt");
add(boxButton);
boxButton.addActionListener( this );
theTextField = new JTextField("Write Something ");
add(theTextField);
theTextField.addActionListener( this );
values = new LinkedList<Double>(); // make the stack
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if ( e.getSource()==theTextField ) {
value1 = Double.parseDouble(theTextField.getText());
values.push(value1);
}
}
public void add() {//return nothing
value1=values.pop();
value2=values.pop();
values.push (value1 + value2);
}
public void multi() { //return nothing
value1=values.pop();
value2=values.pop();
values.push (value1 * value2);
}
public void divide() {//return nothing
value1=values.pop();
value2=values.pop();
values.push (value1 / value2);
}
public void subt() {//return nothing
value1=values.pop();
value2=values.pop();
values.push (value1 - value2);
}
public void paint( Graphics g ) {
Iterator it = values.iterator();
while (it.hasNext()) {
double d = (Double)(it.next());
Double d1 = (Double)(it.next());
System.out.println("d="+d + d1 );
super.paint(g);
//((LinkedList) values).paint(g);
//values = LinkedList.paint(g);
g.create(29, 40, 100, 200); // at the bottom of the screen
//g.drawString( value2, 50,420 );
//g.drawString( values, 50,480 );
}
}