I'm writing an small program in Java to get to know the language, a calculator that only dus plus :P but i want to get it so that you can't type anything but numbers.
Should i do this with a keylistener? and if yes how?
/*
* Created on Feb 23, 2005
* @author R. Knijntje
*
*
*
* This code was designed by R. knijnenburg
* Copyright @ R. Knijnenburg, http://entertainer.no-ip.com, Mondriaan onderwijsgroep
*/
/*
* Created on Feb 24, 2005
* @author R. Knijntje
*
*
*
*
* Created by R. Knijnenburg
* Copyright @ R. Knijnenburg
*/
public class RekenMachineStarter
{
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
RekenMachineView mijnView = new RekenMachineView();
RekenMachineModel mijnModel = new RekenMachineModel();
RekenMachineLuisteraar l = new RekenMachineLuisteraar(mijnModel, mijnView);
mijnView.voegLuisteraarToe(l);
}
}
/*
* Created on Feb 23, 2005
* @author R. Knijntje
*
*
*
* This code was designed by R. knijnenburg
* Copyright @ R. Knijnenburg, http://entertainer.no-ip.com, Mondriaan onderwijsgroep
*/
public class RekenMachineModel
{
private int getal1, getal2;
public void setGetal1(int waarde1)
{
getal1 = waarde1;
}
public void setGetal2(int waarde2)
{
getal2 = waarde2;
}
public int geefOptelling()
{
int som = getal1 + getal2;
return som;
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
/*
* Created on 21-mrt-2005
* @author R. Knijntje
*
*
*
*
* Created by R. Knijnenburg
* Copyright @ R. Knijnenburg
*/
public class RekenMachineLuisteraar implements ActionListener
{
public class RekenMachineValidator
{
}
private RekenMachineModel m;
private RekenMachineView v;
public RekenMachineLuisteraar(RekenMachineModel m , RekenMachineView v)
{
this.m = m;
this.v = v;
}
to capture keyEvents you will need to implement KeyListener interface. This will have I think 4 methods that you will need to implement. and thats it. If you need to further help onthis let me know
Bookmarks