import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;
import java.text.*;
public class Vhea extends Frame implements ActionListener{
JFrame frame;
JPanel panel1, panel2, panel3;
JLabel inputLabel;
JFormattedTextField inputField;
JButton button;
Container contentPane;
JOptionPane optionPane;
String inputTxt="";
public static void main(String[] args) {
Vhea tm = new Vhea();
}
Vhea() {
frame = new JFrame("Midterm in Compiler");
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
//InputField
inputLabel = new JLabel("Input:");
inputField = new JFormattedTextField();
inputField.setValue(inputTxt);
inputField.setColumns(10);
//Scan button
button = new JButton("SCAN");
button.setActionCommand("scan");
button.addActionListener(this);
//Pack
contentPane = frame.getContentPane();
panel1.add(inputLabel);
panel1.add(inputField);
panel1.setBackground(Color.pink);
panel1.add(button);
panel2.setBackground(Color.pink);
panel3.setBackground(Color.pink);
contentPane.add(panel2, BorderLayout.NORTH);
contentPane.add(panel1, BorderLayout.CENTER);
contentPane.add(panel3, BorderLayout.SOUTH);
frame.setSize(300, 100);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setResizable(false);}
public void actionPerformed(ActionEvent ae) {
String s = ae.getActionCommand();
String wordInput=" ";
String msg1=" is a INVALID input";
String msg2=" is a VALID input";
if (s.equals("scan")) {
wordInput=((String)inputField.getValue());
int i=0;
while(i < wordInput.length()){
char a = wordInput.charAt(i);
if (i == 0){
if( a == '$'){
}
else{
i=wordInput.length();
JOptionPane.showMessageDialog(null,wordInput + msg1);
inputField.setValue("");}}
else if (i == 1){
if(Character.isLetter(a) == true){
}
else{
i=wordInput.length();
JOptionPane.showMessageDialog(null,wordInput + msg1);
inputField.setValue("");}}
else{
if(Character.isLetter(a) == true || Character.isDigit(a)== true || a == '_' || a == ' ' ){
}
else{
i=wordInput.length();
JOptionPane.showMessageDialog(null,wordInput + msg1);
inputField.setValue("");}}
i++;}
if (i ==wordInput.length()){
JOptionPane.showMessageDialog(null,wordInput + msg2);
inputField.setValue("");}
}
}
}
... pls help... i cant use ImageIcon..
ImageIcon icon = createImageIcon("bflowers.jpg");