I have got a JAVA exercise to make 3 text fields, with "name", "address" and "postal code" and a button, and when I click the button, set the labels text from name, address, city and postal code, and shows separate images when I wrote 1000, 2000, 3000 or 4000 to the postal code field.. The image names are 1000.jpg, 2000. jpg, 3000.jpg and 4000.jpg. How can I make this, to show a picture)?
I have gave up at this point:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
public class Kepeslap extends Applet implements ActionListener{
TextField nev, cim, irszam;
Button kuld;
Label lnev, lcim, lirszam, varos, knev, kcim, kirszam;
Image belyeg, nyiregyhaza, budapest, tiszabo, csongrad;
public void init(){
setLayout(null);
lnev = new Label("Név:");
lnev.setBounds(5,5,50,20);
add(lnev);
nev = new TextField();
nev.setBounds(55,5,150,20);
add(nev);
lcim = new Label("Lakcím:");
lcim.setBounds(5,30,50,20);
add(lcim);
cim=new TextField();
cim.setBounds(55,30,150,20);
add(cim);
lirszam=new Label("Irányítószám:");
lirszam.setBounds(5,55,145,20);
add(lirszam);
irszam=new TextField();
irszam.setBounds(150,55,55,20);
add(irszam);
kuld=new Button("Nagy, ronda küldés gomb");
kuld.setBounds(210,5,210,75);
add(kuld);
kuld.addActionListener(this);
varos=new Label();
varos.setBounds(500,310,198,20);
add(varos);
knev=new Label();
knev.setBounds(500,250,198,20);
add(knev);
kcim=new Label();
kcim.setBounds(500,280,198,20);
add(kcim);
kirszam=new Label();
kirszam.setBounds(500,340,198,20);
add(kirszam);
}
public void paint (Graphics g){
Color fekete = new Color(0,0,0);
g.setColor(fekete);
g.drawRect(5,90,700,350);
try{URL ut = new URL("http://imagerz.com/QENOC0tvAwINBA1OEgVR");
belyeg=getImage(ut);
g.drawImage(belyeg,570,100,this);}
catch(MalformedURLException mu){}
}
public void actionPerformed(ActionEvent ae){
try{
knev.setText(nev.getText());
kcim.setText(cim.getText());
kirszam.setText(irszam.getText());
Label ir = new Label(irszam.getText());
add(ir);
if (ir.getText().equals("1000")){
varos.setText("Nyíregyháza");
}
else if (ir.getText().equals("2000")){
varos.setText("Budapest");
}
else if (ir.getText().equals("3000")){
varos.setText("Csongrád");
}
else if (ir.getText().equals("4000")){
varos.setText("Tiszabő");
}
else {varos.setText("HIBA!!");
}}
catch (RuntimeException ex){kirszam.setText("HIBA!!");
}}}