Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: national couries

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default national couries

    I have problem with the gui

    first of all, this is my code

    starting pointmain)

    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.swing.*;

    //import com.mysql.jdbc.*;



    public class Courier
    {
    public static void main(String [] a) throws SQLException
    {
    Myframe frame=new Myframe();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    MainPanel panel=new MainPanel();




    /* These are for database
    java.sql.Connection conn=null;
    ResultSet result=null;
    Statement stmt=null;
    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Database name","username","password");
    java.sql.Statement stm=conn.createStatement();
    ResultSet rs = stm.executeQuery("SELECT * FROM offices");
    // */

    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    }
    }

    second main panel:

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.border.*;


    public class MainPanel extends JPanel
    { private JLabel banner,body,user_id,passwords;
    private BufferedImage myHeader=null,myBody=null;
    private JButton buttonOk, buttonCancel;
    private JTextField username;
    private JTextArea text;
    private JPasswordField pass_field;
    private JPanel pnltext,pnluser, pnlpass, pnlButton, pnlbox;
    char[] cmd;
    String user_name=" ",user_input=" ";

    public MainPanel()
    { pass_field=new JPasswordField(10);
    username=new JTextField(10);
    buttonOk=new JButton("OK");
    buttonCancel=new JButton("Cancel");
    user_id=new JLabel("User Id:");
    passwords=new JLabel("Password:");
    ButtonListener listener=new ButtonListener();
    buttonOk.addActionListener(listener);
    buttonCancel.addActionListener(listener);
    Font myFont=new Font("Cooper Black", Font.PLAIN,15);
    text=new JTextArea("Enter your user ID and password here:");

    pnlbox= new JPanel();
    pnlbox.setLayout(new BoxLayout(pnlbox,BoxLayout.Y_AXIS));
    pnlbox.setBackground(Color.white);
    pnlbox.setAlignmentX(CENTER_ALIGNMENT);

    pnltext=new JPanel();
    pnltext.setLayout(new BoxLayout(pnltext,BoxLayout.X_AXIS));
    pnltext.setBackground(Color.white);

    pnluser=new JPanel();
    pnluser.setLayout(new BoxLayout(pnluser,BoxLayout.X_AXIS));
    pnluser.setBackground(Color.white);
    pnluser.setAlignmentX(CENTER_ALIGNMENT);

    pnlpass=new JPanel();
    pnlpass.setLayout(new BoxLayout(pnlpass,BoxLayout.X_AXIS));
    pnlpass.setBackground(Color.white);
    pnlpass.setAlignmentX(CENTER_ALIGNMENT);

    pnlButton=new JPanel();
    pnlButton.setBackground(Color.white);


    pnlbox.setBorder(BorderFactory.createTitledBorder( null,"Login Panel", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, myFont));
    pnltext.add(text);

    pnluser.add(user_id);
    pnluser.add(Box.createRigidArea(new Dimension (30,10)));
    pnluser.add(username);

    pnlpass.add(passwords);
    pnlpass.add(Box.createRigidArea(new Dimension (11,0)));
    pnlpass.add(pass_field);

    pnlButton.add(buttonOk);
    pnlButton.add(buttonCancel);

    pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
    pnlbox.add(pnltext);
    pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
    pnlbox.add(pnluser);
    pnlbox.add(Box.createRigidArea(new Dimension (20,10)));
    pnlbox.add(pnlpass);
    pnlbox.add(Box.createRigidArea(new Dimension (0,5)));
    pnlbox.add(pnlButton);

    try
    { myHeader = ImageIO.read(new File("Resized-SX2HH.jpg"));
    myBody=ImageIO.read(new File("body.jpg"));
    }
    catch (IOException e){}
    banner=new JLabel(new ImageIcon(myHeader));
    body=new JLabel(new ImageIcon(myBody));
    body.setAlignmentX(LEFT_ALIGNMENT);



    Panel pnlheader=new Panel();
    pnlheader.setLayout(new BorderLayout());
    pnlheader.setLocation(10,35);
    pnlheader.add(banner, BorderLayout.NORTH);
    pnlheader.add(body, BorderLayout.WEST);


    pnlheader.add(pnlbox, BorderLayout.EAST);

    add(pnlheader);

    setPreferredSize (new Dimension(1357,1100));
    }
    private class ButtonListener implements ActionListener, MouseListener
    {

    public void actionPerformed(ActionEvent e)
    { user_name=username.getText(); //user input username
    cmd=pass_field.getPassword();
    user_input=new String(cmd); //user input password here

    if (e.getSource()==buttonOk)
    {


    JOptionPane.showMessageDialog(null, "Welcome ");
    }
    else
    System.exit(0);
    }

    public void mousePressed(MouseEvent e){ }
    public void mouseReleased(MouseEvent e){ }
    public void mouseClicked(MouseEvent e){ }
    public void mouseEntered(MouseEvent e)
    {
    if (e.getSource()==buttonOk)
    buttonOk.setBackground(Color.green);
    }
    public void mouseExited(MouseEvent e)
    {
    if (e.getSource()==buttonOk) //Color color = new Color(204,204,204);
    buttonOk.setBackground(null);
    }
    }
    }

    screen shot
    problem.jpg

    As you can see there, login panel is like worsh. Actually, I want to make it fix with the small scale..please I need help because I'm the beginner.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: national couries

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: national couries

     
    <import java.awt.image.BufferedImage;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.swing.*;
     
    //import com.mysql.jdbc.*;
     
     
     
    public class Courier
    {
    public static void main(String [] a) throws SQLException
    { 
    Myframe frame=new Myframe();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    MainPanel panel=new MainPanel();
     
     
     
     
    /* These are for database
    java.sql.Connection conn=null;
    ResultSet result=null; 
    Statement stmt=null; 
    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Database name","username","password");
    java.sql.Statement stm=conn.createStatement();
    ResultSet rs = stm.executeQuery("SELECT * FROM offices");
    // */
     
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    }
    }
     
    second main panel:
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.border.*;
     
     
    public class MainPanel extends JPanel
    { private JLabel banner,body,user_id,passwords;
    private BufferedImage myHeader=null,myBody=null;
    private JButton buttonOk, buttonCancel;
    private JTextField username;
    private JTextArea text;
    private JPasswordField pass_field;
    private JPanel pnltext,pnluser, pnlpass, pnlButton, pnlbox;
    char[] cmd;
    String user_name=" ",user_input=" ";
     
    public MainPanel()
    { pass_field=new JPasswordField(10);
    username=new JTextField(10);
    buttonOk=new JButton("OK");
    buttonCancel=new JButton("Cancel");
    user_id=new JLabel("User Id:");
    passwords=new JLabel("Password:");
    ButtonListener listener=new ButtonListener();
    buttonOk.addActionListener(listener);
    buttonCancel.addActionListener(listener); 
    Font myFont=new Font("Cooper Black", Font.PLAIN,15);
    text=new JTextArea("Enter your user ID and password here:");
     
    pnlbox= new JPanel();
    pnlbox.setLayout(new BoxLayout(pnlbox,BoxLayout.Y_AXIS));
    pnlbox.setBackground(Color.white);
    pnlbox.setAlignmentX(CENTER_ALIGNMENT);
     
    pnltext=new JPanel();
    pnltext.setLayout(new BoxLayout(pnltext,BoxLayout.X_AXIS));
    pnltext.setBackground(Color.white);
     
    pnluser=new JPanel();
    pnluser.setLayout(new BoxLayout(pnluser,BoxLayout.X_AXIS));
    pnluser.setBackground(Color.white);
    pnluser.setAlignmentX(CENTER_ALIGNMENT);
     
    pnlpass=new JPanel();
    pnlpass.setLayout(new BoxLayout(pnlpass,BoxLayout.X_AXIS));
    pnlpass.setBackground(Color.white);
    pnlpass.setAlignmentX(CENTER_ALIGNMENT);
     
    pnlButton=new JPanel();
    pnlButton.setBackground(Color.white);
     
     
    pnlbox.setBorder(BorderFactory.createTitledBorder( null,"Login Panel", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, myFont));
    pnltext.add(text);
     
    pnluser.add(user_id);
    pnluser.add(Box.createRigidArea(new Dimension (30,10)));
    pnluser.add(username);
     
    pnlpass.add(passwords);
    pnlpass.add(Box.createRigidArea(new Dimension (11,0)));
    pnlpass.add(pass_field);
     
    pnlButton.add(buttonOk); 
    pnlButton.add(buttonCancel);
     
    pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
    pnlbox.add(pnltext);
    pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
    pnlbox.add(pnluser);
    pnlbox.add(Box.createRigidArea(new Dimension (20,10)));
    pnlbox.add(pnlpass);
    pnlbox.add(Box.createRigidArea(new Dimension (0,5)));
    pnlbox.add(pnlButton);
     
    try
    { myHeader = ImageIO.read(new File("Resized-SX2HH.jpg"));
    myBody=ImageIO.read(new File("body.jpg"));
    }
    catch (IOException e){}
    banner=new JLabel(new ImageIcon(myHeader));
    body=new JLabel(new ImageIcon(myBody));
    body.setAlignmentX(LEFT_ALIGNMENT);
     
     
     
    Panel pnlheader=new Panel();
    pnlheader.setLayout(new BorderLayout());
    pnlheader.setLocation(10,35);
    pnlheader.add(banner, BorderLayout.NORTH);
    pnlheader.add(body, BorderLayout.WEST);
     
     
    pnlheader.add(pnlbox, BorderLayout.EAST);
     
    add(pnlheader);
     
    setPreferredSize (new Dimension(1357,1100));
    }
    private class ButtonListener implements ActionListener, MouseListener
    { 
     
    public void actionPerformed(ActionEvent e)
    { user_name=username.getText(); //user input username
    cmd=pass_field.getPassword();
    user_input=new String(cmd); //user input password here 
     
    if (e.getSource()==buttonOk)
    { 
     
     
    JOptionPane.showMessageDialog(null, "Welcome ");
    }
    else
    System.exit(0);
    }
     
    public void mousePressed(MouseEvent e){ }
    public void mouseReleased(MouseEvent e){ }
    public void mouseClicked(MouseEvent e){ }
    public void mouseEntered(MouseEvent e)
    {
    if (e.getSource()==buttonOk)
    buttonOk.setBackground(Color.green);
    }
    public void mouseExited(MouseEvent e)
    {
    if (e.getSource()==buttonOk) //Color color = new Color(204,204,204);
    buttonOk.setBackground(null);
    }
    }
    } >


    --- Update ---

     
    <import java.awt.image.BufferedImage;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import javax.swing.*;
     
    //import com.mysql.jdbc.*;
     
     
     
    public class Courier
    {
    public static void main(String [] a) throws SQLException
    { 
    Myframe frame=new Myframe();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    MainPanel panel=new MainPanel();
     
     
     
     
    /* These are for database
    java.sql.Connection conn=null;
    ResultSet result=null; 
    Statement stmt=null; 
    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Database name","username","password");
    java.sql.Statement stm=conn.createStatement();
    ResultSet rs = stm.executeQuery("SELECT * FROM offices");
    // */
     
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    }
    }
     
    second main panel:
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.border.*;
     
     
    public class MainPanel extends JPanel
    { private JLabel banner,body,user_id,passwords;
    private BufferedImage myHeader=null,myBody=null;
    private JButton buttonOk, buttonCancel;
    private JTextField username;
    private JTextArea text;
    private JPasswordField pass_field;
    private JPanel pnltext,pnluser, pnlpass, pnlButton, pnlbox;
    char[] cmd;
    String user_name=" ",user_input=" ";
     
    public MainPanel()
    { pass_field=new JPasswordField(10);
    username=new JTextField(10);
    buttonOk=new JButton("OK");
    buttonCancel=new JButton("Cancel");
    user_id=new JLabel("User Id:");
    passwords=new JLabel("Password:");
    ButtonListener listener=new ButtonListener();
    buttonOk.addActionListener(listener);
    buttonCancel.addActionListener(listener); 
    Font myFont=new Font("Cooper Black", Font.PLAIN,15);
    text=new JTextArea("Enter your user ID and password here:");
     
    pnlbox= new JPanel();
    pnlbox.setLayout(new BoxLayout(pnlbox,BoxLayout.Y_AXIS));
    pnlbox.setBackground(Color.white);
    pnlbox.setAlignmentX(CENTER_ALIGNMENT);
     
    pnltext=new JPanel();
    pnltext.setLayout(new BoxLayout(pnltext,BoxLayout.X_AXIS));
    pnltext.setBackground(Color.white);
     
    pnluser=new JPanel();
    pnluser.setLayout(new BoxLayout(pnluser,BoxLayout.X_AXIS));
    pnluser.setBackground(Color.white);
    pnluser.setAlignmentX(CENTER_ALIGNMENT);
     
    pnlpass=new JPanel();
    pnlpass.setLayout(new BoxLayout(pnlpass,BoxLayout.X_AXIS));
    pnlpass.setBackground(Color.white);
    pnlpass.setAlignmentX(CENTER_ALIGNMENT);
     
    pnlButton=new JPanel();
    pnlButton.setBackground(Color.white);
     
     
    pnlbox.setBorder(BorderFactory.createTitledBorder( null,"Login Panel", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, myFont));
    pnltext.add(text);
     
    pnluser.add(user_id);
    pnluser.add(Box.createRigidArea(new Dimension (30,10)));
    pnluser.add(username);
     
    pnlpass.add(passwords);
    pnlpass.add(Box.createRigidArea(new Dimension (11,0)));
    pnlpass.add(pass_field);
     
    pnlButton.add(buttonOk); 
    pnlButton.add(buttonCancel);
     
    pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
    pnlbox.add(pnltext);
    pnlbox.add(Box.createRigidArea(new Dimension (40,10)));
    pnlbox.add(pnluser);
    pnlbox.add(Box.createRigidArea(new Dimension (20,10)));
    pnlbox.add(pnlpass);
    pnlbox.add(Box.createRigidArea(new Dimension (0,5)));
    pnlbox.add(pnlButton);
     
    try
    { myHeader = ImageIO.read(new File("Resized-SX2HH.jpg"));
    myBody=ImageIO.read(new File("body.jpg"));
    }
    catch (IOException e){}
    banner=new JLabel(new ImageIcon(myHeader));
    body=new JLabel(new ImageIcon(myBody));
    body.setAlignmentX(LEFT_ALIGNMENT);
     
     
     
    Panel pnlheader=new Panel();
    pnlheader.setLayout(new BorderLayout());
    pnlheader.setLocation(10,35);
    pnlheader.add(banner, BorderLayout.NORTH);
    pnlheader.add(body, BorderLayout.WEST);
     
     
    pnlheader.add(pnlbox, BorderLayout.EAST);
     
    add(pnlheader);
     
    setPreferredSize (new Dimension(1357,1100));
    }
    private class ButtonListener implements ActionListener, MouseListener
    { 
     
    public void actionPerformed(ActionEvent e)
    { user_name=username.getText(); //user input username
    cmd=pass_field.getPassword();
    user_input=new String(cmd); //user input password here 
     
    if (e.getSource()==buttonOk)
    { 
     
     
    JOptionPane.showMessageDialog(null, "Welcome ");
    }
    else
    System.exit(0);
    }
     
    public void mousePressed(MouseEvent e){ }
    public void mouseReleased(MouseEvent e){ }
    public void mouseClicked(MouseEvent e){ }
    public void mouseEntered(MouseEvent e)
    {
    if (e.getSource()==buttonOk)
    buttonOk.setBackground(Color.green);
    }
    public void mouseExited(MouseEvent e)
    {
    if (e.getSource()==buttonOk) //Color color = new Color(204,204,204);
    buttonOk.setBackground(null);
    }
    }
    } >

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: national couries

    What are the problems you are facing? Ask an appropriate question and get reasonable answer from here. I suppose, you have gone through the Forums Rules?
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford