0

I have a Sign up form.Below the form there is a JLabel 'Already have an account?'.I need to create a Linked Label here with 'Sign in' text.how to do that?

In the code below there are two lables such as 'Already have an account?' and 'sign in'. I need to make 'sign in' Lable as a Link to open another GUI form which is made for sign in.How to do that?

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

public class Stackoverflow extends JFrame implements ActionListener {

    private Container c;
    private JLabel lable;
    private JLabel signin;
    public Stackoverflow() {

        setTitle("Login");
        setBounds(300,90,400,200);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        c= getContentPane();
        c.setLayout(null);

        lable = new JLabel("Already have an account?");
        lable.setFont(new Font("Arial",Font.ITALIC,12));
        lable.setSize(300,20);
        lable.setLocation(50,100);
        c.add(lable);

        signin = new JLabel("Sign in");
        signin.setFont(new Font("Arial",Font.ITALIC,12));
        signin.setSize(300,20);
        signin.setLocation(200,100);
        c.add(signin);

        setVisible(true);

    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }
}
public class Main {

    public static void main(String[] args) {
        Stackoverflow stack = new Stackoverflow();
    }
}


Jeewantha Lahiru
  • 324
  • 2
  • 4
  • 15
  • 1) `c.setLayout(null);` Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and borders for [white space](http://stackoverflow.com/a/17874718/418556). 2) `setBounds(..);` once the layout is fixed, replace that with `pack();` and either `setLocationRelativeTo(null); // middle of screen` or `setLocationByPlatform(true); // where OS says` – Andrew Thompson Jan 19 '20 at 08:19
  • 3) Note that a log-in would more commonly appear in a `JDialog` (`setLocationRelativeTo(null);` or with location relative to an existing window) as opposed to a `JFrame` (`setLocationByPlatform(true)`). – Andrew Thompson Jan 19 '20 at 08:26

0 Answers0