powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Нужна помощь с простым
2 сообщений из 2, страница 1 из 1
Нужна помощь с простым
    #38966915
Yuras4
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Мне нужна это программа для изучения языка как пример .

Не прикручиваеться к кнопке запуск класса .
Не получаеться вывести часы в одном окне з кнопками .

Главный класс.

package test;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Date;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.Timer;

public class Test extends JFrame{

public static void main(String args[]) {
JFrame frame = new JFrame("SwingDefaultButton");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ClockLabel clock = new ClockLabel();
getContentPane().add(clock, BorderLayout.NORTH);

Man ourMan= new Man();
ourMan.Menit();

Test ct = new Test();
ct.setVisible(true);

Container content = frame.getContentPane();
content.setLayout(new GridLayout(2, 2));

JButton button1 = new JButton("Ip");
button1.setMnemonic(KeyEvent.VK_B);
content.add(button1);

Icon warnIcon = new ImageIcon("Warn.gif");
JButton button2 = new JButton(warnIcon);
content.add(button2);

JButton button3 = new JButton("Warning", warnIcon);
content.add(button3);

String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
+ "<font color=\"#FF0080\"><u>Multi-line</u></font>";
JButton button4 = new JButton(htmlButton);
content.add(button4);

JRootPane rootPane = frame.getRootPane();
rootPane.setDefaultButton(button2);

frame.setSize(300, 200);
frame.setVisible(true);

// ClockLabel clock = new ClockLabel();
// getContentPane().add(clock, BorderLayout.NORTH);
}

//public static void main(String args[]) {
//ClockTest ct = new ClockTest();
//ct.setVisible(true);
}
//}
class ClockLabel extends JLabel implements ActionListener {

public ClockLabel() {
super("" + new Date());
Timer t = new Timer(1000, this);
t.start();
}

public void actionPerformed(ActionEvent ae) {
setText((new Date()).toString());
}
}


Вторичный
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class Man {
public static void main(String [] args) {

public void Menit(){

JFrame frame = new JFrame("Current IP");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
String IP = "";
try {
IP = InetAddress.getLocalHost().getHostAddress();
}
catch (Exception e) {
IP = "Error finding IP";
}

JPanel panel = new JPanel();

panel.setBorder(BorderFactory.createTitledBorder(" Current IP Address"));
panel.add(new JLabel(" " + IP + " "));

frame.getContentPane().add(panel);

frame.pack();

frame.setVisible(true);
}
}
...
Рейтинг: 0 / 0
Нужна помощь с простым
    #38966956
Nixic
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
package test;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Date;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRootPane;
import javax.swing.Timer;

public class Test extends JFrame{

public static void main(String args[]) {
JFrame frame = new JFrame("SwingDefaultButton");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ClockLabel clock = new ClockLabel();
getContentPane().add(clock, BorderLayout.NORTH);

Man ourMan= new Man();
ourMan.Menit();

Test ct = new Test();
ct.setVisible(true);

Container content = frame.getContentPane();
content.setLayout(new GridLayout(2, 2));

JButton button1 = new JButton("Ip");
button1.setMnemonic(KeyEvent.VK_B);
content.add(button1);

Icon warnIcon = new ImageIcon("Warn.gif");
JButton button2 = new JButton(warnIcon);
content.add(button2);

JButton button3 = new JButton("Warning", warnIcon);
content.add(button3);

String htmlButton = "<html><sup>HTML</sup> <sub><em>Button</em></sub><br>"
+ "<font color=\"#FF0080\"><u>Multi-line</u></font>";
JButton button4 = new JButton(htmlButton);
content.add(button4);

JRootPane rootPane = frame.getRootPane();
rootPane.setDefaultButton(button2);

frame.setSize(300, 200);
frame.setVisible(true);

// ClockLabel clock = new ClockLabel();
// getContentPane().add(clock, BorderLayout.NORTH);
}

//public static void main(String args[]) {
//ClockTest ct = new ClockTest();
//ct.setVisible(true);
}
//}
class ClockLabel extends JLabel implements ActionListener {

public ClockLabel() {
super("" + new Date());
Timer t = new Timer(1000, this);
t.start();
}

public void actionPerformed(ActionEvent ae) {
setText((new Date()).toString());
}
}


Вторичный
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class Man {
public static void main(String [] args) {

public void Menit(){

JFrame frame = new JFrame("Current IP");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
String IP = "";
try {
IP = InetAddress.getLocalHost().getHostAddress();
}
catch (Exception e) {
IP = "Error finding IP";
}

JPanel panel = new JPanel();

panel.setBorder(BorderFactory.createTitledBorder(" Current IP Address"));
panel.add(new JLabel(" " + IP + " "));

frame.getContentPane().add(panel);

frame.pack();

frame.setVisible(true);
}
}
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Нужна помощь с простым
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]