Results 1 to 3 of 3
  1. #1
    KevinQ is offline Member
    Join Date
    Jun 2011
    Posts
    1
    Rep Power
    0

    Default How can I get a GUI preview on java source code

    I just download some GUI source codes in Java. It's not a SWING GUI form , but I wish to preview that GUI just as the design view .
    Code as follows:
    import javax.swing.JPanel;
    import javax.swing.JLabel;

    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JTextField;
    import javax.swing.JPasswordField;
    import javax.swing.JComboBox;
    import javax.swing.JButton;

    import org.jdesktop.swingx.JXBusyLabel;

    public class UserLoginUI extends JPanel implements ActionListener {

    private static final long serialVersionUID = 1L;
    private JLabel jLabelUsername = null;
    private JLabel jLabelPassword = null;
    private JTextField jTextFieldUsername = null;
    private JPasswordField jPasswordFieldPassword = null;
    private JButton jButtonSubmit = null;
    private LoginListener loginListener;
    private JXBusyLabel jBusyLabel = null;

    /**
    * This is the default constructor
    */
    public UserLoginUI() {
    super();
    initialize();
    }

    /**
    *
    * Add a listener that will be notified for login
    * @param listener
    */
    public void setLoginListener(LoginListener listener){
    this.loginListener = listener;
    }

    /**
    * This method initializes this
    *
    * @return void
    */
    private void initialize() {
    jBusyLabel = new JXBusyLabel();
    jBusyLabel.setBusy(true);
    jBusyLabel.setVisible(false);
    jBusyLabel.setBounds(new Rectangle(87, 165, 161, 31));
    jBusyLabel.setText("Authenticating......");
    jLabelPassword = new JLabel();
    jLabelPassword.setBounds(new Rectangle(61, 90, 72, 16));
    jLabelPassword.setText("Password");
    jLabelUsername = new JLabel();
    jLabelUsername.setBounds(new Rectangle(61, 61, 65, 16));
    jLabelUsername.setText("User Name");
    this.setLayout(null);
    this.setPreferredSize(new Dimension(300, 222));
    this.add(jLabelUsername, null);
    this.add(jLabelPassword, null);
    this.add(getJTextFieldUsername(), null);
    this.add(getJPasswordFieldPassword(), null);
    this.add(getJButtonSubmit(), null);
    this.add(jBusyLabel, null);
    }



    public void setBusy(boolean state){
    jBusyLabel.setVisible(state);
    }

    /**
    * This method initializes jTextFieldUsername
    *
    * @return javax.swing.JTextField
    */
    private JTextField getJTextFieldUsername() {
    if (jTextFieldUsername == null) {
    jTextFieldUsername = new JTextField();
    jTextFieldUsername.setBounds(new Rectangle(150, 61, 106, 20));
    }
    return jTextFieldUsername;
    }

    /**
    * This method initializes jPasswordFieldPassword
    *
    * @return javax.swing.JPasswordField
    */
    private JPasswordField getJPasswordFieldPassword() {
    if (jPasswordFieldPassword == null) {
    jPasswordFieldPassword = new JPasswordField();
    jPasswordFieldPassword.setBounds(new Rectangle(150, 91, 106, 20));
    }
    return jPasswordFieldPassword;
    }

    /**
    * This method initializes jButtonSubmit
    *
    * @return javax.swing.JButton
    */
    private JButton getJButtonSubmit() {
    if (jButtonSubmit == null) {
    jButtonSubmit = new JButton();
    jButtonSubmit.setBounds(new Rectangle(117, 131, 88, 26));
    jButtonSubmit.setText("Submit");
    jButtonSubmit.addActionListener(this);

    }
    return jButtonSubmit;
    }

    /* (non-Javadoc)
    * @see java.awt.event.ActionListener#actionPerformed(java .awt.event.ActionEvent)
    * Whenever a mouse button is pressed notify the LoginListener
    */
    @Override
    public void actionPerformed(ActionEvent event) {



    if(event.getSource()== getJButtonSubmit()){


    jBusyLabel.setVisible(true);
    jBusyLabel.repaint();
    String username = getJTextFieldUsername().getText();
    String password = new String(getJPasswordFieldPassword().getPassword());
    if(loginListener != null){
    loginListener.login(username,password);
    }



    }

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Please read the forum rules to which you agreed when you signed up to the site:
    Forum Rules
    Your other two threads have been deleted.

    Also check the BB Code list to learn how to post code
    BB Code List - Java Forums

    To answer your question, you can't. Not in any reasonable way at least. But what you can do is learn Swing and not depend on someone else's code, or a visual designer (which is an advanced tool) for your homework.
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    db

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

Similar Threads

  1. Get source code from java file
    By rjagan in forum New To Java
    Replies: 1
    Last Post: 04-04-2011, 10:51 AM
  2. Need help on writing Java source code
    By k4it0xtr3me in forum New To Java
    Replies: 29
    Last Post: 01-24-2011, 03:56 PM
  3. Can we Obtain Java Source Code?
    By tornado in forum New To Java
    Replies: 7
    Last Post: 12-10-2008, 07:23 PM
  4. Replies: 1
    Last Post: 11-28-2008, 06:27 PM
  5. open source java code
    By reena in forum Advanced Java
    Replies: 1
    Last Post: 04-19-2008, 06:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •