- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.*;
public class Experiment5 implements ActionListener{
JFrame frame;
JList list;
JTextField text;
public static void main(String[] args) {
Experiment5 experiment5 = new Experiment5();
experiment5.go();
}
public void go(){
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
JButton button = new JButton("Click me");
button.addActionListener(this);
text = new JTextField();
String[] listEntries = {"Java", "C++", "Perl", "Python", "JavaScript", "PHP", "C#"};
list = new JList(listEntries);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(new SelectionOne());
MyDrawPanel1 panel1 = new MyDrawPanel1();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.NORTH, text);
frame.getContentPane().add(BorderLayout.EAST, list);
frame.getContentPane().add(BorderLayout.CENTER, panel1);
frame.setSize(500, 300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
int ran = (int) (Math.random() * 255);
text.setText("New random - " + ran);
frame.repaint();
}
class SelectionOne implements ListSelectionListener {
public void valueChanged(ListSelectionEvent lse) {
if(!lse.getValueIsAdjusting()){
String selection = (String) list.getSelectedValue();
System.out.println(selection);
}
}
}
}
class MyDrawPanel1 extends JPanel{
public void paintComponent(Graphics g){
int one = (int)(Math.random() * 255);
int two = (int)(Math.random() * 255);
int three = (int)(Math.random() * 255);
Color color = new Color(one, two, three);
g.setColor(color);
g.fillOval(110, 10, 200, 200);
}
}
SWING!!! Jlist, JTextField, JPanel !!! КАК УЛУЧШИТЬ ЭТОТ ПОНОС???
cykablyad2 22.12.2017 19:21 # 0
bormand 23.12.2017 00:50 # 0
Десктопный клиент для ГК?