DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Creating first GUI Java Program (http://www.daniweb.com/forums/thread18875.html)

AQWst Feb 19th, 2005 1:40 am
Creating first GUI Java Program
 
I am new to GUI Java programming and I am attempting to find the best way of creating a frame to contain a series of menus. I am first adding logic to have the date and time appear in the frame, but the way I am doing it they are both showing up on the same line and I can't seem to find any sources on how to get these and additional text to appear on separate lines. I will include my source to have someone look at it or tear it apart. May I ask that some one please point me in the right direction to a source to this type of programming or offer me some advice on a better method of doing this simple task?
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*;

public class InitialFrame1 extends JFrame
{
        public InitialFrame1()
        {
        setSize(800, 625);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container pane = getContentPane();
        FlowLayout flo = new FlowLayout();
        pane.setLayout(flo);
        InitialPanel Date = new InitialPanel();
        pane.add(Date);
        setContentPane(Date);
        InitialPanel Time = new InitialPanel();
        pane.add(Time);
        setContentPane(Time);
        setVisible(true);
        }

public static void main (String[] arguments)
{
        InitialFrame1 a1 = new InitialFrame1();
}
       
public class InitialPanel extends JPanel
{
        public InitialPanel()
        {
        String Current_Date = getDate();
        JLabel Date = new JLabel(Current_Date);
        Date.setForeground(Color.blue);
        add(Date);
        String Current_Time = getTime();
        JLabel Time = new JLabel(Current_Time);
        Time.setForeground(Color.blue);
        add(Time);

        } 

        String getDate()
{
String Date;
 // get current Date
    Calendar now = Calendar.getInstance();
    int month = now.get(Calendar.MONTH) + 1;
    int day = now.get(Calendar.DAY_OF_MONTH);
    int year = now.get(Calendar.YEAR);
 
    Date = month + "/" + day + "/" + year;
    return Date;       
}

        String getTime()
{
String Time;
 // get current Time
    Calendar now = Calendar.getInstance();
    int hour = now.get(Calendar.HOUR_OF_DAY);
    int minute = now.get(Calendar.MINUTE);
    int second = now.get(Calendar.SECOND);
 
    Time = hour + ":" + minute + ":" + second;
    return Time;       
}
 
}
}

BountyX Feb 19th, 2005 2:18 am
Re: Creating first GUI Java Program
 
pane.getContentPane().add(Date, flo.TOP); // can be TOP, RIGHT, BOTTOM, LEFT
pane.getContentPane().add(Time, flo.BOTTOM); // can be TOP, RIGHT, BOTTOM, LEFT

Heres the java documentation for JFrame: http://java.sun.com/j2se/1.4.2/docs/...ng/JFrame.html

jwenting Feb 19th, 2005 2:40 am
Re: Creating first GUI Java Program
 
Use BorderLayout, not FlowLayout, for your main frame.
Then put the menu in TOP and the main content in CENTER (in which you may have to add JPanels with their own layout managers to get the effect you want).

sandesh_daddi Feb 19th, 2005 5:24 am
Help Friend
 
hi friend i am not telling to how to code in java because i m also new to java i am doing my MCA in pune (INDIA) in FIRST SEM i m ne wto this programming :D




i want to know that how to post my quries to every one i read that select forum and click new thread button but i can't saw :cry: any such button

so please HELP ME

we have projrcts in JAVA if u know any project title please tell me it will only for 50 marks and without data base .

plz HELP MI

server_crash Feb 19th, 2005 9:01 am
Re: Creating first GUI Java Program
 
You should post a seperate thread, so that you don't distract away from this thread starter.

tigerxx Feb 23rd, 2005 3:41 am
Re: Help Friend
 
Quote:

Originally Posted by sandesh_daddi
hi friend i am not telling to how to code in java because i m also new to java i am doing my MCA in pune (INDIA) in FIRST SEM i m ne wto this programming :D




i want to know that how to post my quries to every one i read that select forum and click new thread button but i can't saw :cry: any such button

so please HELP ME

we have projrcts in JAVA if u know any project title please tell me it will only for 50 marks and without data base .

plz HELP MI


u can go for a image processing in java

can go in GUI manner

shinnxennosagga Mar 8th, 2008 1:22 am
Re: Creating first GUI Java Program
 
I' not sure guys, but I don't think there's TOP or BOTTOM constant in FlowLayout or BorderLayout, for FlowLayout, there're only LEFT, RIGHT, and CENTER. For BorderLayout, there're CENTER, SOUTH, NORTH, WEST, and EAST.

darkagn Mar 8th, 2008 1:53 am
Re: Creating first GUI Java Program
 
Hi there shinnxennosagga,

Please check the date of threads before posting a reply to them - you have just resurrected a thread that hasn't been used for three years...

jwenting Mar 8th, 2008 2:00 am
Re: Creating first GUI Java Program
 
and giving an answer that's incorrect too...

gap_89 Nov 11th, 2009 3:14 am
hey can u help me by dis problem
write down an application to display a window with various GUI components available in the awt packages


All times are GMT -4. The time now is 3:33 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC