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