import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
class frame extends JFrame implements ActionListener{
JTextField a,b,c;
JLabel str,hr,angk;
JButton hur,ang;
//public boolean aa=true;
public static void main(String[] args){
frame e = new frame();
}
frame(){
super("Pemisahan String");
setSize(250,250);
str=new JLabel("String : ");
hr=new JLabel("Huruf : ");
angk=new JLabel("Angka : ");
a= new JTextField(10);
b=new JTextField(10);
c=new JTextField(10);
JPanel p=new JPanel();
p.setLayout(new GridLayout(3,2));
p.add(str);p.add(a);
p.add(hr);p.add(b);
p.add(angk);p.add(c);
getContentPane().add("North",p);
hur=new JButton("HURUF");
ang=new JButton("ANGKA");
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(1,2));
p1.add(hur);p1.add(ang);
getContentPane().add("South",p1);
hur.addActionListener(this);
ang.addActionListener(this);
show();
}
public void actionPerformed(ActionEvent e){
String q,r;
if(e.getSource()==hur){
//aa=true;
q=a.getText();
String ff=new String("1234567890");
StringTokenizer st=new StringTokenizer(q,ff,false);
while(st.hasMoreTokens()){
b.setText(st.nextToken()); }
}
else
if(e.getSource()==ang){
//aa=true;
r=a.getText();
String gh=new String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
StringTokenizer ft=new StringTokenizer(r,gh,false);
while(ft.hasMoreTokens()){
c.setText(ft.nextToken());
}
}
}
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar