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;	
} 
 
} 
}

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).

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

You should post a seperate thread, so that you don't distract away from this thread starter.

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

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.

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...

and giving an answer that's incorrect too...

commented: good point +1

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

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

You revived an old thread, when the best advice would be to use the javax.swing package.

dis s Zen ,

please help me to mke program in java that has GUI its hard for me to mke coz i can't understand... please give me some tips thank you!!! this is my project and I can't think well coz I'm sick....

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*;

public class InitialFrame1 extends JFrame
{
<b>Container pane;</b>
	public InitialFrame1()
	{
	setSize(800, 85);
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	pane = getContentPane();
	
	[B]//FlowLayout flo = new FlowLayout();
	//pane.setLayout(flo);[/B]
	pane.setLayout(new GridLayout(3,1));
	InitialPanel Date = new InitialPanel();
	pane.add(Date); 
        [B]//setContentPane(Date);
	//InitialPanel Time = new InitialPanel();
	//pane.add(Time);
	//setContentPane(Time);[/B]
	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); 
	 [B]pane.add(Date);[/B] 
         String Current_Time = getTime();
	 JLabel Time = new JLabel(Current_Time);
	 Time.setForeground(Color.blue); 
	 [B]pane.add(Time); 
[/B]
	}  

	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;	
} 
 
} 
}

Hello Mr. ... I am rajesh. I have given you the code according to your requirement.
I have bolded the reqired changes.
Please go through the code.And try to understand the changes i made to programm.
If dont understand the changes please reply me with prog. i'll give you the description
also.

Have happy programming and for coming diwali.

dis s Zen ,

please help me to mke program in java that has GUI its hard for me to mke coz i can't understand... please give me some tips thank you!!! this is my project and I can't think well coz I'm sick....

Zen ... first of all, if you had taken the time to read the post before yours, you should have known not to post here but to start a new thread
secondly, try to learn english. not everyone here has english as mother tongue, but since english is very common, in the IT sector not the least, we do try to help you in this language, but, we are trying to understand 'english', not the
"1m n0t l3rng 3nglsh, cz 4m l33z4"

next ... what do you want us to help you with? a program in java that has GUI? are we talking a Swing Gui, a web-interface, a command prompt gui, ... ?

and last but not least: the rules of the site require you to put in some effort yourself, this is not a "hire-a-pr0grammer" site. we help you develop your skills by helping you understanding and correcting mistakes in your code, not just write custom-made-applications for you. if you are to sick to work on it, you're also to sick to post threads like this.

Hello Mr. ... I am rajesh. I have given you the code according to your requirement.
I have bolded the reqired changes.
Please go through the code.And try to understand the changes i made to programm.
If dont understand the changes please reply me with prog. i'll give you the description
also.

Have happy programming and for coming diwali.

Rajesh ... how on earth could you give him code "according to his requirements"??? he hasn't specified any requirements.

next to that, we appreciate the effort of you helping new developers increasing their skills, so for that part, welcome to DaniWeb, but don't just hand out custom-made code, that way they won't learn anything, they'll just copy and paste your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.