java程序,想问问为什么窗口内没有内容
package exp_08;
public class Ques9_2 {
public static void main(String[] args) {
WindowFrameCal cal=new WindowFrameCal();
cal.setTitle("计算");
cal.setBounds(100,100,500,300);
}
}
package exp_08;
import javax.swing.*;
import java.awt.*;
public class WindowFrameCal extends JFrame {
Box box;
JTextField input1,input2,output;
JButton[]buttons = new JButton[4];
Cal ca;
JPanel panel;
JLabel label;
WindowFrameCal()
{
init();
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
void init()
{
box = Box.createVerticalBox();
panel =new JPanel();
input1=new JTextField(10);
input2=new JTextField(10);
output=new JTextField(10);
buttons[0] = new JButton("加");
buttons[1] = new JButton("减");
buttons[2] = new JButton("乘");
buttons[3] = new JButton("除");
Font f = new Font("宋体",Font.BOLD,28);
SetFont.setFont
(f,input1,input2,output,buttons[0],buttons[1],buttons[2],buttons[3]);
panel.add(input1);
panel.add(input2);
panel.add(output);
panel.add(box);
for(int i=0;i<buttons.length;i++)
{
buttons[i].addActionListener(ca);
box.add(buttons[i]);
}
}
}
package exp_08;
import java.awt.event.*;
import javax.swing.*;
public class Cal implements ActionListener {
WindowFrameCal view;
public void setView(WindowFrameCal view)
{
this.view=view;
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==view.buttons[0]) {
try {
double a = Double.parseDouble(view.input1.getText());
double b = Double.parseDouble(view.input2.getText());
double ans = a+b;
view.output.setText("" + ans);
} catch (NumberFormatException ex) {
System.out.println("输入非法字符 " + ex.getMessage());
}
}
else if(e.getSource()==view.buttons[1])
{
try {
double a = Double.parseDouble(view.input1.getText());
double b = Double.parseDouble(view.input2.getText());
double ans = a-b;
view.output.setText("" + ans);
} catch (NumberFormatException ex) {
System.out.println("输入非法字符 " + ex.getMessage());
}
}
else if(e.getSource()==view.buttons[2])
{
try {
double a = Double.parseDouble(view.input1.getText());
double b = Double.parseDouble(view.input2.getText());
double ans = a*b;
view.output.setText("" + ans);
}
catch (NumberFormatException ex) {
System.out.println("输入非法字符 " + ex.getMessage());
}
}
else if(e.getSource()==view.buttons[3])
{
try {
double a = Double.parseDouble(view.input1.getText());
double b = Double.parseDouble(view.input2.getText());
double ans = a/b;
view.output.setText("" + ans);
}
catch (NumberFormatException ex) {
System.out.println("输入非法字符 " + ex.getMessage());
}
}
}
}