在java中,如何在标签里每秒显示一下当前系统时间
4个回答
展开全部
public class MyDesktopPane extends JFrame implements ActionListener {
final static JDesktopPane desktopPane = new JDesktopPane();
public MyDesktopPane() {
super("MyDesktopPane.java:DesktopPane测试");
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("新增窗口");
JMenuItem menultem = new JMenuItem("内部框架窗口");
menu.add(menultem);
menuBar.add(menu);
setJMenuBar(menuBar);
getContentPane().add(desktopPane);
menultem.addActionListener(this);
setSize(350, 200);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
JInternalFrame inFrame = new JInternalFrame("内部框架(圆环)", true, true, true, true);
Container c = inFrame.getContentPane();
CirclePanel circlePanel = new CirclePanel();
JLabel label = new JLabel("圆环");
c.add(circlePanel, BorderLayout.CENTER);
c.add(label, BorderLayout.WEST);
int w = circlePanel.getImageWidthHeight().width + 150;
int h = circlePanel.getImageWidthHeight().height + 50;
inFrame.setSize(w, h);
inFrame.reshape(100, 50, w, h);
inFrame.setOpaque(true);
desktopPane.add(inFrame);
inFrame.setVisible(true);
}
public static void main(String args[]) {
MyDesktopPane app = new MyDesktopPane();
app.addWindowListener(new MyWindowListener());
}
}
class CirclePanel extends JPanel {
private ImageIcon imglcon;
public CirclePanel() {
try {
imglcon = new ImageIcon(new URL(""));
} catch (MalformedURLException ex) {
Logger.getLogger(CirclePanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void paint(Graphics g) {
g.drawImage(imglcon.getImage(), 0, 0, this);
}
public Dimension getImageWidthHeight() {
return new Dimension(imglcon.getIconWidth(), imglcon.getIconHeight());
}
}
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(1);
}
}
final static JDesktopPane desktopPane = new JDesktopPane();
public MyDesktopPane() {
super("MyDesktopPane.java:DesktopPane测试");
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("新增窗口");
JMenuItem menultem = new JMenuItem("内部框架窗口");
menu.add(menultem);
menuBar.add(menu);
setJMenuBar(menuBar);
getContentPane().add(desktopPane);
menultem.addActionListener(this);
setSize(350, 200);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
JInternalFrame inFrame = new JInternalFrame("内部框架(圆环)", true, true, true, true);
Container c = inFrame.getContentPane();
CirclePanel circlePanel = new CirclePanel();
JLabel label = new JLabel("圆环");
c.add(circlePanel, BorderLayout.CENTER);
c.add(label, BorderLayout.WEST);
int w = circlePanel.getImageWidthHeight().width + 150;
int h = circlePanel.getImageWidthHeight().height + 50;
inFrame.setSize(w, h);
inFrame.reshape(100, 50, w, h);
inFrame.setOpaque(true);
desktopPane.add(inFrame);
inFrame.setVisible(true);
}
public static void main(String args[]) {
MyDesktopPane app = new MyDesktopPane();
app.addWindowListener(new MyWindowListener());
}
}
class CirclePanel extends JPanel {
private ImageIcon imglcon;
public CirclePanel() {
try {
imglcon = new ImageIcon(new URL(""));
} catch (MalformedURLException ex) {
Logger.getLogger(CirclePanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void paint(Graphics g) {
g.drawImage(imglcon.getImage(), 0, 0, this);
}
public Dimension getImageWidthHeight() {
return new Dimension(imglcon.getIconWidth(), imglcon.getIconHeight());
}
}
class MyWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(1);
}
}
展开全部
我建议是使用js代码来实现系统时间的实现,而不需要系统每秒从服务器返回一个值来客户端上。
参考资料: sername
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
js中有关于显示时间的对象Date, 如:var date=new Date(); date.get**(); 自己查一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
建议用线程试试!
希望对你有帮助……
希望对你有帮助……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询