Jframe에 더 많은 컨테이너를 추가하려면 어떻게해야합니까? 너희들이 날이 난 것 작동하도록 도움을 줄 수있는 경우jframe에 컨테이너 추가하기
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;
public class CopyOftheclock {
public static void main(String[] args) {
JFrame clock = new TextClockWindow();
clock.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
clock.setVisible(true);
}
}
@SuppressWarnings("serial")
class TextClockWindow extends JFrame {
private JTextField timeField;
public TextClockWindow() {
timeField = new JTextField(7);
timeField.setFont(new Font("sansserif", Font.PLAIN, 48));
Container content = this.getContentPane();
content.setLayout(new FlowLayout());
content.add(timeField);
this.setTitle("Norway");
this.pack();
javax.swing.Timer t = new javax.swing.Timer(1000,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
String a = "";
Calendar now = Calendar.getInstance();
int h = now.get(Calendar.HOUR_OF_DAY);
if (h==24)
{
h=8;
a = "A.M";
}
if (h==1)
{
h=9;
a = "A.M";
}
if (h==2)
{
h=10;
a = "A.M";
}
if (h==3)
{
h=11;
a = "A.M";
}
if (h==4)
{
h=12;
a = "P.M";
}
if (h==5)
{
h=1;
a = "P.M";
}
if (h==6)
{
h=2;
a = "P.M";
}
if (h==7)
{
h=3;
a = "P.M";
}
if (h==8)
{
h=4;
a = "P.M";
}
if (h==9)
{
h=5;
a = "P.M";
}
if (h==10)
{
h=6;
a = "P.M";
}
if (h==11)
{
h=7;
a = "P.M";
}
if (h==12)
{
h=8;
a = "P.M";
}
if (h==13)
{
h=9;
a = "P.M";
}
if (h==14)
{
h=10;
a = "P.M";
}
if (h==15)
{
h=11;
a = "P.M";
}
if (h==16)
{
h=12;
a = "P.M";
}
if (h==17)
{
h=1;
a = "A.M";
}
if (h==18)
{
h=2;
a = "A.M";
}
if (h==19)
{
h=3;
a = "A.M";
}
if (h==20)
{
h=4;
a = "A.M";
}
if (h==21)
{
h=5;
a = "A.M";
}
if (h==22)
{
h=6;
a = "A.M";
}
if (h==23)
{
h=7;
a = "A.M";
}
int m = now.get(Calendar.MINUTE);
int s = now.get(Calendar.SECOND);
timeField.setText("" + h + ":" + m + ":" + s + " " + a);
}
});
t.start();
}
}
: Heres는 코드 내 라인은 내가 heres는, 같은 JFrame의 측면에서 다른 시계를 포함하는 하나 개의 창에서 시계를 만들어 내 코드를 싶습니다 정말 감사합니다!
내가 무엇을하려고하는지 사진이 있습니다. http://s1173.photobucket.com/albums/r597/jackiechanwins/?action=view¤t=clock.jpg –
'add()'메소드를 사용하면 어떻게됩니까? –
코드에 어디에 넣을까요? 각 컨테이너는 다른 숫자를 갖게 될 것입니다. –