Softhema Group
This is an applet example for the method isLike in the class ToolkitString
Source code:
import softhema.system.toolkits.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AppletIsLike extends Applet
{
Panel panel1 = new Panel();
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
Label label4 = new Label();
BorderLayout borderLayout1 = new BorderLayout();
Label label5 = new Label();
Panel panel2 = new Panel();
BorderLayout borderLayout2 = new BorderLayout();
Panel panel3 = new Panel();
FlowLayout flowLayout1 = new FlowLayout();
Button btnExample1 = new Button();
Button btnExample2 = new Button();
Button btnExample3 = new Button();
Button btnExample4 = new Button();
Button btnExample5 = new Button();
Button btnExample6 = new Button();
Panel panel4 = new Panel();
BorderLayout borderLayout3 = new BorderLayout();
Panel panel5 = new Panel();
FlowLayout flowLayout2 = new FlowLayout();
Checkbox chkIgnoreCase = new Checkbox();
Checkbox chkExtended = new Checkbox();
Panel panel6 = new Panel();
BorderLayout borderLayout4 = new BorderLayout();
Panel panel7 = new Panel();
TextArea txtText = new TextArea();
TextArea txtPattern = new TextArea();
Label label7 = new Label();
Label lblText = new Label();
GridBagLayout gridBagLayout1 = new GridBagLayout();
Panel panel8 = new Panel();
BorderLayout borderLayout5 = new BorderLayout();
Button btnExecute = new Button();
Label lblText1 = new Label();
Panel panel9 = new Panel();
BorderLayout borderLayout6 = new BorderLayout();
TextField txtResult = new TextField();
BorderLayout borderLayout7 = new BorderLayout();
Button btnExample7 = new Button();
public AppletIsLike()
{
try
{
jbInit();
setBackground( SystemColor.control );
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void jbInit() throws Exception
{
this.setLayout(borderLayout1);
panel1.setLayout(borderLayout2);
label5.setText("boolean result = ToolkitString.isLike( text , pattern );");
panel2.setLayout(borderLayout3);
panel3.setLayout(flowLayout1);
btnExample1.setLabel("Example1");
btnExample1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExample1_actionPerformed(e);
}
});
btnExample2.setLabel("Example2");
btnExample2.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExample2_actionPerformed(e);
}
});
btnExample3.setLabel("Example3");
btnExample3.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExample3_actionPerformed(e);
}
});
btnExample4.setLabel("Example4");
btnExample4.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExample4_actionPerformed(e);
}
});
btnExample5.setLabel("Example5");
btnExample5.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExample5_actionPerformed(e);
}
});
btnExample6.setLabel("Example6");
btnExample6.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExample6_actionPerformed(e);
}
});
panel4.setLayout(borderLayout4);
panel5.setLayout(flowLayout2);
chkIgnoreCase.setLabel("Ignore case");
chkExtended.setLabel("Extended");
panel6.setLayout(borderLayout5);
panel7.setLayout(gridBagLayout1);
label7.setText("pattern:");
lblText.setText("text:");
panel8.setLayout(borderLayout6);
btnExecute.setLabel("Compare text and pattern (isLike)");
btnExecute.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExecute_actionPerformed(e);
}
});
lblText1.setText("result:");
panel9.setLayout(borderLayout7);
borderLayout6.setVgap(5);
borderLayout5.setVgap(5);
txtResult.setEditable(false);
btnExample7.setLabel("Example7");
btnExample7.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
btnExample7_actionPerformed(e);
}
});
this.add(panel1, BorderLayout.CENTER);
panel1.add(label5, BorderLayout.NORTH);
panel1.add(panel2, BorderLayout.CENTER);
panel2.add(panel3, BorderLayout.NORTH);
panel3.add(btnExample1, null);
panel3.add(btnExample2, null);
panel3.add(btnExample3, null);
panel3.add(btnExample4, null);
panel3.add(btnExample5, null);
panel3.add(btnExample6, null);
panel3.add(btnExample7, null);
panel2.add(panel4, BorderLayout.CENTER);
panel4.add(panel5, BorderLayout.NORTH);
panel5.add(chkIgnoreCase, null);
panel5.add(chkExtended, null);
panel4.add(panel6, BorderLayout.CENTER);
panel6.add(panel7, BorderLayout.NORTH);
GridBagConstraints gridBag = new GridBagConstraints();
gridBag.gridx = 0;
gridBag.gridy = 0;
gridBag.gridwidth = 1;
gridBag.gridheight = 1;
gridBag.weightx = 0.0;
gridBag.weighty = 0.0;
gridBag.anchor = GridBagConstraints.WEST;
gridBag.fill = GridBagConstraints.NONE;
gridBag.insets = new Insets(0, 0, 0, 0);
gridBag.ipadx = 43;
gridBag.ipady = 63;
panel7.add(lblText, gridBag);
gridBag = new GridBagConstraints();
gridBag.gridx = 1;
gridBag.gridy = 0;
gridBag.gridwidth = 1;
gridBag.gridheight = 1;
gridBag.weightx = 1.0;
gridBag.weighty = 1.0;
gridBag.anchor = GridBagConstraints.CENTER;
gridBag.fill = GridBagConstraints.BOTH;
gridBag.insets = new Insets(0, 0, 0, 0);
gridBag.ipadx = -67;
gridBag.ipady = -84;
panel7.add(txtText, gridBag);
gridBag = new GridBagConstraints();
gridBag.gridx = 0;
gridBag.gridy = 1;
gridBag.gridwidth = 1;
gridBag.gridheight = 1;
gridBag.weightx = 0.0;
gridBag.weighty = 0.0;
gridBag.anchor = GridBagConstraints.WEST;
gridBag.fill = GridBagConstraints.NONE;
gridBag.insets = new Insets(15, 0, 0, 0);
gridBag.ipadx = 43;
gridBag.ipady = 63;
panel7.add(label7, gridBag);
gridBag = new GridBagConstraints();
gridBag.gridx = 1;
gridBag.gridy = 1;
gridBag.gridwidth = 1;
gridBag.gridheight = 1;
gridBag.weightx = 1.0;
gridBag.weighty = 1.0;
gridBag.anchor = GridBagConstraints.CENTER;
gridBag.fill = GridBagConstraints.BOTH;
gridBag.insets = new Insets(15, 0, 0, 0);
gridBag.ipadx = -66;
gridBag.ipady = -84;
panel7.add(txtPattern, gridBag);
panel6.add(panel8, BorderLayout.CENTER);
panel8.add(btnExecute, BorderLayout.NORTH);
panel8.add(panel9, BorderLayout.CENTER);
panel9.add(lblText1, BorderLayout.WEST);
panel9.add(txtResult, BorderLayout.CENTER);
this.add(label1, BorderLayout.NORTH);
this.add(label2, BorderLayout.EAST);
this.add(label3, BorderLayout.SOUTH);
this.add(label4, BorderLayout.WEST);
}
void btnExecute_actionPerformed(ActionEvent e)
{
try
{
String sText = txtText.getText();
String sPattern = txtPattern.getText();
if( chkExtended.getState() )
{
if( chkIgnoreCase.getState() )
{
txtResult.setText( String.valueOf( ToolkitString.isLikeExIgnoreCase( sText, sPattern ) ) );
}
else
{
txtResult.setText( String.valueOf( ToolkitString.isLikeEx( sText, sPattern ) ) );
}
}
else
{
if( chkIgnoreCase.getState() )
{
txtResult.setText( String.valueOf( ToolkitString.isLikeIgnoreCase( sText, sPattern ) ) );
}
else
{
txtResult.setText( String.valueOf( ToolkitString.isLike( sText, sPattern ) ) );
}
}
}
catch( Exception x )
{
x.printStackTrace();
txtResult.setText(x.getClass().getName() + ";" + x.getMessage());
}
}
void btnExample1_actionPerformed(ActionEvent e)
{
chkExtended.setState(false);
chkIgnoreCase.setState(false);
txtText.setText("Hello world");
txtPattern.setText("* world");
txtResult.setText("Press Button");
}
void btnExample2_actionPerformed(ActionEvent e)
{
chkExtended.setState(false);
chkIgnoreCase.setState(true);
txtText.setText("Hello world");
txtPattern.setText("h?ll? *or*ld");
txtResult.setText("Press Button");
}
void btnExample3_actionPerformed(ActionEvent e)
{
chkExtended.setState(true);
chkIgnoreCase.setState(true);
txtText.setText("Hello world");
txtPattern.setText("[a-i]ello*[u-w]orld");
txtResult.setText("Press Button");
}
void btnExample4_actionPerformed(ActionEvent e)
{
chkExtended.setState(true);
chkIgnoreCase.setState(true);
txtText.setText("Hello world");
txtPattern.setText("Hi world");
txtResult.setText("Press Button");
}
void btnExample5_actionPerformed(ActionEvent e)
{
chkExtended.setState(true);
chkIgnoreCase.setState(true);
txtText.setText("Hello world");
txtPattern.setText("H[def]??o w*[def]");
txtResult.setText("Press Button");
}
void btnExample6_actionPerformed(ActionEvent e)
{
chkExtended.setState(true);
chkIgnoreCase.setState(true);
txtText.setText("name=value");
txtPattern.setText("*=*");
txtResult.setText("Press Button");
}
void btnExample7_actionPerformed(ActionEvent e)
{
chkExtended.setState(true);
chkIgnoreCase.setState(true);
txtText.setText("Hello world");
txtPattern.setText("h[^*d]d");
txtResult.setText("Press Button");
}
}