D
einfacher ist es natürlich alle Funktionen durch implements hinzuzufügen:
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.util.Vector;
import TestPackage.ITest;
import TestPackage.TestEnum;
public class TestApplet extends Applet implements ActionListener, ITest
{
private static final long serialVersionUID = 1L;
Button okButton;
Button wrongButton;
TextField nameField;
CheckboxGroup radioGroup;
Checkbox radio1;
Checkbox radio2;
Checkbox radio3;
public String getAppletInfo()
{
return "TestApplet Version 1.0.0";
}
void ResultHandlerTestCallback(TestEnum myenum,Vector<byte[]> vrgubData)
{
nameField.setText("Read");
repaint();
}
public void init()
{
// Now we will use the FlowLayout
setLayout(new FlowLayout());
okButton = new Button("Action!");
wrongButton = new Button("Don't click!");
nameField = new TextField("abcdefghijklm",35);
radioGroup = new CheckboxGroup();
radio1 = new Checkbox("Red", radioGroup,false);
radio2 = new Checkbox("Blue", radioGroup,true);
radio3 = new Checkbox("Green", radioGroup,false);
setSize(400,200);
add(okButton);
// Attach actions to the components
okButton.addActionListener(this);
wrongButton.addActionListener(this);
}
public void destroy()
{
CallbackTestInterface = null;
}
// When the button is clicked this method will get automatically called
// This is where you specify all actions.
public void actionPerformed(ActionEvent evt)
{
// Here we will ask what component called this method
if (evt.getSource() == okButton)
{
// So it was the okButton, then let's perform his actions
// reader.SyncGetEPCs();
// Let the applet perform Paint again.
// That will cause the aplet to get the text out of the textField
// again and show it.
repaint();
}
// Actions of the wrongButton
else if (evt.getSource() == wrongButton)
{
// Change the text on the button for fun
wrongButton.setLabel("Not here!");
// Changes the text in the TextField
nameField.setText("That was the wrong button!");
// Lets the applet show that message.
repaint();
}
}
// Here we will show the results of our actions
public void paint(Graphics g)
{
// If the radio1 box is selected then radio1.getState() will
// return true and this will execute
if (radio1.getState()) g.setColor(Color.red);
// If it was not red we'll try if it is blue
else if (radio2.getState()) g.setColor(Color.blue);
// Since always one radiobutton must be selected it must be green
else g.setColor(Color.green);
// Now that the color is set you can get the text out the TextField
// like this
g.drawString(nameField.getText(),20,100);
}
@Override
public void ResultHandlerTest(TestEnum myenum, Vector<byte[]> vrgubData) {
// TODO Auto-generated method stub
}
}