Untitled
unknown
java
a month ago
1.8 kB
5
Indexable
Never
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class GraphicalInterface implements ActionListener { JFrame jf = new JFrame(); JLabel welcomeText = new JLabel(); JLabel username = new JLabel(); JTextArea UNI = new JTextArea(); JLabel pass = new JLabel(); JTextArea PI = new JTextArea(); JButton login = new JButton(); JLabel show = new JLabel(); public void actionPerformed(ActionEvent e) { if (e.getSource() == login) { if (UNI.getText().equals("abcd") && PI.getText().equals(("123"))) { System.out.println("Successful"); show.setText("Successful"); } else { System.out.println("Try again"); show.setText("Try again"); } } } public GraphicalInterface() { welcomeText.setBounds(140, 5, 100, 50); username.setBounds(50, 50, 100, 50); UNI.setBounds(200, 50, 100, 50); pass.setBounds(50, 150, 100, 50); PI.setBounds(200, 150, 100, 50); login.setBounds(120, 250, 100, 50); show.setBounds(135, 350, 100, 50); jf.add(welcomeText); jf.add(username); jf.add(UNI); jf.add(pass); jf.add(PI); jf.add(login); jf.add(show); welcomeText.setText("WELCOME!"); username.setText("Username"); pass.setText("Password"); login.setText("Login"); login.addActionListener(this); jf.setLocation(50, 50); jf.setSize(365,480); jf.setLayout(null); jf.setVisible(true); } public static void main(String[] args) { new GraphicalInterface(); } }
Leave a Comment