Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.home;
- import java.awt.BorderLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class Prasanna {
- public void showGUI() {
- JFrame jf = new JFrame(); // Creates new JFrame in Memory
- jf.setTitle("Prasanna"); // Sets title of jf to Prasanna
- jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Sets the X mark/Alt+F4 control to exit app
- jf.setSize(200,100); // Gives size to the Frame to fill objects
- JButton jb = new JButton("Press Me"); // Create a button object
- JTextField jtf = new JTextField(20);
- JLabel jl = new JLabel("Do Something",JLabel.CENTER);
- jf.add(jtf,BorderLayout.NORTH);
- jf.add(jl, BorderLayout.CENTER);
- jb.addActionListener(new myAction(jtf,jl));
- jf.add(jb, BorderLayout.SOUTH); // Creates a new Button in that JFrame
- jf.setVisible(true);
- }
- public class myAction implements ActionListener
- {
- JLabel jl;
- JTextField jtf;
- public myAction(JTextField jtf, JLabel jl) {
- this.jtf = jtf;
- this.jl = jl;
- }
- public void actionPerformed(ActionEvent prasannaEvent) {
- jl.setText("You typed " + this.jtf.getText());
- }
- }
- public static void main(String[] args) {
- Prasanna p = new Prasanna();
- p.showGUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement