Java JDialog

0
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;


import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Frame extends JFrame implements ActionListener
{	
	public PanelDodaj pD;
	
	private  JButton bDodaj, bClean;
	JTextArea _resultArea = new JTextArea(6, 20);
	
	public Frame()
	{
		setLayout(null);
		
		
		bDodaj = new JButton("Dodaj");
		bDodaj.setBounds(20,20,100,20);
		add(bDodaj);
		bDodaj.addActionListener(this);
		
		bClean = new JButton("Wyczyść");
		bClean.setBounds(130,20,100,20);
		add(bClean);
		bClean.addActionListener(this);
		// JTextArea
		
        JScrollPane scrollingArea = new JScrollPane(_resultArea);
        scrollingArea.setBounds(20, 50, 200, 200);
        add(_resultArea);
        _resultArea.setBounds(20, 50, 200 , 200);
        _resultArea.setOpaque(true);
		_resultArea.setWrapStyleWord(true);
		add(scrollingArea);
		
		
		
		Font font = new Font("Cambria", Font.PLAIN, 12);
		_resultArea.setFont(font);
		_resultArea.setForeground(Color.BLUE);
	}
	public void actionPerformed(ActionEvent e)
	{
		Object z = e.getSource();
			if(z==bClean)
			{
				if(pD==null)
					pD= new PanelDodaj(this);
				pD.setVisible(true);
				pD.setFocus();
			
				if(pD.isOK())
				{
				_resultArea.append(pD.getName()+" "+" "+pD.getprice());
				}
			pD.setVisible(false);
			
			}
			
		}
	

	public static void main(String[] args) 
	{
		// JFrame
		Frame ramka = new Frame();
		ramka.setDefaultCloseOperation(3);
		ramka.setVisible(true);
		ramka.setSize(250, 300);
		ramka.setResizable(false);
		ramka.setLocation(560, 250);
		ramka.setTitle("Check OUT!");
		//T E S T :D
		
		
		
	}
	
	class PanelDodaj extends JDialog implements ActionListener
	{
			private JLabel lname, lprice, lamount;
			private JTextField tname, tprice, tamount;
			private JButton bOK, bCancel;
			
			private boolean okData;
			
			public PanelDodaj(JFrame owner)
			
			{
				super(owner, "Wprowadzanie", true);
				setSize(220,200);
				setLayout(null);
				
				lname = new JLabel ("Nazwa :", JLabel.RIGHT);
				lname.setBounds(20, 20, 50, 20);
				add(lname);
				
				lprice = new JLabel ("Cena :", JLabel.RIGHT);
				lprice.setBounds(20, 50, 50, 20);
				add(lprice);
				
				lamount = new JLabel ("Ilość :", JLabel.RIGHT);
				lamount.setBounds(20, 80, 50, 20);
				add(lamount);
				
				tname = new JTextField ();
				tname.setBounds(80, 20, 50, 20);
				add(tname);
				
				tprice = new JTextField ();
				tprice.setBounds(80, 50, 50, 20);
				add(tprice);
				
				tprice = new JTextField ();
				tprice.setBounds(80, 80, 50, 20);
				add(tprice);
				
				bOK = new JButton("OK");
				bOK.setBounds(20, 110, 80, 20);
				bOK.addActionListener(this);
				add(bOK);
				
				bCancel = new JButton("Cancel");
				bCancel.setBounds(110, 110, 80, 20);
				bCancel.addActionListener(this);
				add(bCancel);
			}
		public String gettname()
		{
			return tname.getText();
		}
		
		public int getprice()
		{
			
			return  Integer.parseInt(tprice.getText());
		}
		public int getamount()
		{
			return  Integer.parseInt(tamount.getSelectedText());
			
		}
		public boolean isOK()
		{
			return okData;
		}
		public void setFocus()
		{
			tname.requestFocusInWindow();
			tprice.requestFocusInWindow();

		}
		public void actionPerformed(ActionEvent a) 
		{
			Object z = a.getSource();
			if (z==bOK)
			{
				okData = true;
			}
			else
			{
				okData=false;
			}
			
		}
	

}
}

  • i błędy **

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "a"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at Frame$PanelDodaj.getprice(Frame.java:150)
at Frame.actionPerformed(Frame.java:68)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

0

Podpowiedź: <ciągu znaków "a" nie da się przekonwertować do inta>

1 użytkowników online, w tym zalogowanych: 0, gości: 1