0
我無法理解如何在我的任務中執行以下步驟,我想要具有Exception超類構造函數是什麼意思?我會在哪裏把那個設置例外
這裏只是EmptyFieldException類
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class EmptyFieldException
{
EmptyFieldException()
{
}
}
這裏是我的應用程序,其中大部分的工作是做
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
public class AccountApplet extends JApplet implements ActionListener
{
// For West
public JLabel ai = new JLabel("Account ID ");
public JTextField aitf = new JTextField();
public JLabel ab = new JLabel("Account Balance ");
public JTextField abtf = new JTextField();
// For East
public JButton dp = new JButton ("Deposit");
public JTextField dptf = new JTextField();
public JButton wt = new JButton ("Withdraw");
public JTextField wttf = new JTextField();
// For South
public JLabel status = new JLabel("placeholder");
public void init()
{
this.setSize(400, 90);
//----------------------
// Set up the Structure
//----------------------
Container c = getContentPane();
JPanel b = new JPanel(new BorderLayout());
JPanel west = new JPanel(new GridLayout(2,2));
JPanel east = new JPanel(new BorderLayout());
JPanel depo_with = new JPanel(new GridLayout(2,2));
// Add BorderLayout to the container
c.add(b);
// Add everything to West
b.add(west, BorderLayout.WEST);
west.setBorder(new TitledBorder("Display Account Information"));
west.add(ai);
west.add(aitf);
aitf.setEditable(false);
west.add(ab);
west.add(abtf);
abtf.setEditable(false);
// Add everything to EAST
b.add(east, BorderLayout.EAST);
east.setBorder(new TitledBorder("Deposit or Withdrawl Funds"));
east.add(depo_with, BorderLayout.EAST);
depo_with.add(dptf);
depo_with.add(dp);
depo_with.add(wttf);
depo_with.add(wt);
dp.addActionListener(this);
wt.addActionListener(this);
// Add everything to EAST
b.add(status, BorderLayout.SOUTH);
} // End intit
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == dp) // Executes if deposit was clicked
{
}
if (e.getSource() == wt) // Executes if withdraw was clicked
{
}
} // End actionPerformed
public void refreshFields()
{
// diplays accound id and balance in left text fields
//should be called when the applet is first displayed and after each valid transaction
}
public double getAmount(JTextField tf) //throws EmptyFieldException,
// NumberFormatException,
// NegativeAmountException
{
return 5.0;
} // End getAmount
} // End Class
似乎你已經安裝? –
您的異常不會擴展Exception類,因此您只需擁有一個不是Throwable或可捕捉的普通Java類 –
擴展異常並使用超級調用來調用超類構造函數。 https://docs.oracle.com/javase/tutorial/java/IandI/super.html – ManoDestra