英文:
Can we make a internet based Java Swing GUI?
问题
以下是您提供的Java代码的翻译部分:
import java.awt.event.*;
import java.util.Calendar;
import javax.swing.*;
import java.awt.*;
public class DigitalTimer implements ActionListener {
JFrame f = new JFrame("数字时钟");
JLabel l;
JLabel l2;
public DigitalTimer() {
f.setSize(250, 150);
Font font = new Font("Arial", Font.ITALIC, 24);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel clk = new JPanel();
clk.setLayout(new BoxLayout(clk, BoxLayout.PAGE_AXIS));
f.add(clk);
l = new JLabel();
l2 = new JLabel();
clk.add(l2);
clk.add(l);
Timer refresher = new Timer(1000, this);
refresher.start();
l2.setFont(font);
l2.setText("HH:MM:SS");
f.setVisible(true);
}
public static void main(String[] args) {
DigitalTimer dTimer;
dTimer = new DigitalTimer();
}
public void actionPerformed(ActionEvent e) {
f.setVisible(true);
Font font1 = new Font("Arial", Font.PLAIN, 26);
Calendar calendar;
calendar = Calendar.getInstance();
int hour;
hour = calendar.get(Calendar.HOUR_OF_DAY);
int min;
min = calendar.get(Calendar.MINUTE);
int sec;
sec = calendar.get(Calendar.SECOND);
l.setFont(font1);
l.setText(hour + ":" + min + ":" + sec);
}
}
输出:
如果可能的话,如何通过数据库在远程访问中显示 DigitalTimer GUI?
英文:
Made a java Swing GUI which shows Standard Time. How can it be connected to internet? I mean I want to show the same GUI in other PC located remotely.
Java code:
import java.awt.event.*;
import java.util.Calendar;
import javax.swing.*;
import java.awt.*;
public class DigitalTimer implements ActionListener
{
JFrame f=new JFrame("DiGi ClOcK");
JLabel l;
JLabel l2;
public DigitalTimer()
{
f.setSize(250,150);
Font font=new Font("Arial",Font.ITALIC,24);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel clk = new JPanel();
clk.setLayout(new BoxLayout(clk,BoxLayout.PAGE_AXIS));
f.add(clk);
l = new JLabel();
l2=new JLabel();
clk.add(l2);
clk.add(l);
Timer refresher = new Timer(1000,this);
refresher.start();
l2.setFont(font);
l2.setText("HH:MM:SS");
f.setVisible(true);
}
public static void main(String[]args)
{
DigitalTimer dTimer;
dTimer = new DigitalTimer();
}
public void actionPerformed(ActionEvent e)
{
f.setVisible(true);
Font font1=new Font("Arial",Font.PLAIN,26);
Calendar calendar;
calendar = Calendar.getInstance();
int hour;
hour = calendar.get(Calendar.HOUR_OF_DAY);
int min;
min = calendar.get(Calendar.MINUTE);
int sec;
sec = calendar.get(Calendar.SECOND);
l.setFont(font1);
l.setText(hour + ":" + min + ":" + sec);
}
}
Output:
How to show the DigitalTimer GUI in a remote access, if possible using database?
专注分享java语言的经验与见解,让所有开发者获益!
评论