Skip to main content

First GUI application using advance Java


import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

class layout implements ActionListener
{
  JFrame jframe;
  JButton jbutton;
  JTextField jtf1;
  JTextField jtf2;
  layout()
  {
  GUI();
  action();
  jframe.setVisible(true);
  }
  void GUI()
  {
  jframe=new JFrame("My Layout");
  jframe.setSize(500,500);
  jframe.setDefaultCloseOperation(jframe.EXIT_ON_CLOSE);
  jbutton=new JButton("Check");
  jtf1=new JTextField("enter string here");
  jtf2=new JTextField();
  jframe.add(jbutton,BorderLayout.CENTER);
  jframe.add(jtf1,BorderLayout.NORTH);
  jframe.add(jtf2,BorderLayout.SOUTH);
  }
  void action()
  {
  jbutton.addActionListener(this);
  }
public void actionPerformed(ActionEvent ae)
  {
  if(ae.getActionCommand().equals("Check"))
  {
    String mk=jtf1.getText();
mk=' '+mk;
char ch=' ';
String str="";
int l=mk.lastIndexOf(' ');
for(int i=0;i<l;i++)
{
ch=mk.charAt(i);
if(ch==' ')
{
str=str+mk.charAt(i+1);
str=str+' ';
}
}
str=str+mk.substring(l);
jtf2.setText(str);
  }
  }
  public static void main(String args[])
  {
  new layout();
  }
}

Comments

Popular posts from this blog

unix commands