G
Guest
Gast
Wie kann ich ein BigInteger Objekt in einen String casten?
MFG
MFG
static BigInteger factorial( int n )
{
BigInteger result = BigInteger.ONE;
if ( n == 0 || n == 1 )
return result;
if ( n > 1 )
for ( int i = 1; i <= n; i++ )
result = result.multiply( BigInteger.valueOf(i) );
return result;
}
final JLabel bl18= new JLabel ("Fakultät:");//Fakultät
bl18.setSize(100,20);
bl18.setLocation(360,170);
f.add(bl18);
bl18.setVisible(false);
final JTextField bt18 = new JTextField ();
bt18.setSize(120,20);
bt18.setLocation(360,190);
f.add(bt18);
bt18.setVisible(false);
final JLabel bl38 = new JLabel ("=");
bl38.setSize(10,20);
bl38.setLocation(495,190);
f.add(bl38);
bl38.setVisible(false);
final JLabel bl58 = new JLabel ("");
bl58.setSize(120,20);
bl58.setLocation(510,190);
f.add(bl58);
bl58.setVisible(false);
final JButton bb18 = new JButton ("Fakultät");
bb18.setSize(120,20);
bb18.setLocation(360,215);
f.add(bb18);
bb18.setVisible(false);
ActionListener fakultaet = new ActionListener() {
public void actionPerformed( ActionEvent e ) {
System.out.println(e);
bt18.setText(bt18.getText().replace(",","."));
String str=factorial(Integer.parseInt(bt17.getText())).toString();
bl58.setText(str);
}
};
bb18.addActionListener(fakultaet);//ende Fakultät
java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=Fakultät,when=1200488683021,modifiers=Button1] on javax.swing.JButton[,360,215,120x20,alignmentX=0.0,alignmentY=0.5,border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@dc8569,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=Fakultät,defaultCapable=true]
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at mt.Tool$10.actionPerformed(Tool.java:932)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)