Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.
YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.
2.3 Vererbung, Konstruktor und Redefinition<br />
public Card(String title, String firstName, String familyName,<br />
String street, String zipCode, String city) {<br />
this.title = title;<br />
this.firstName = firstName;<br />
this.familyName = familyName;<br />
this.street = street;<br />
this.zipCode = zipCode;<br />
this.city = city;<br />
setTitle(firstName);<br />
setSize(240,160);<br />
setResizable(false);<br />
setVisible(true);<br />
}<br />
}<br />
public void paint(Graphics g) {<br />
g.setFont(new Font("Helvetica",Font.PLAIN,12));<br />
g.drawString(title+" "+firstName+" "+familyName,60,60);<br />
g.drawString(street,60,75);<br />
g.setFont(new Font("Helvetica",Font.BOLD,12));<br />
g.drawString(zipCode+" "+city,60,90);<br />
}<br />
public class UserFrame extends Frame implements ActionListener{<br />
private TextField firstName, familyName, street, zipCode, city;<br />
private CheckboxGroup title;<br />
private void place(Component comp,int x,int y,int width,int height) {<br />
comp.setBounds(x, y, width, height);<br />
add(comp);<br />
}<br />
}<br />
public UserFrame() {<br />
Button button;<br />
setTitle("Business Cards");<br />
setLayout(null);<br />
setSize(200,300);<br />
setResizable(false);<br />
title = new CheckboxGroup();<br />
place(new Checkbox("Mr",true,title),30,30,40,20);<br />
place(new Checkbox("Mrs",false,title),80,30,40,20);<br />
place(new Checkbox("Ms",false,title),130,30,40,20);<br />
place(new Label("FirstName"),30,50,140,20);<br />
place(firstName=new TextField(),30,70,140,20);<br />
place(new Label("FamilyName"),30,100,140,20);<br />
place(familyName=new TextField(),30,120,140,20);<br />
place(new Label("Street"),30,150,140,20);<br />
place(street=new TextField(),30,170,140,20);<br />
place(new Label("ZipCode"),30,200,60,20);<br />
place(zipCode=new TextField(),30,220,60,20);<br />
place(new Label("City"),100,200,70,20);<br />
place(city=new TextField(),100,220,70,20);<br />
place(button=new Button("CARD"),70,260,60,20);<br />
button.addActionListener(this);<br />
setVisible(true);<br />
40