Form1
This commit is contained in:
parent
c1a5d23a36
commit
8562c126a2
@ -7,6 +7,8 @@ import javax.swing.Timer;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
|
|
||||||
public class FormTrain{
|
public class FormTrain{
|
||||||
|
public DrawingTrain SelectedTrain;
|
||||||
|
public boolean DialogResult = false;
|
||||||
private DrawingTrain _drawingTrain;
|
private DrawingTrain _drawingTrain;
|
||||||
private AbstractStrategy abstractStrategy;
|
private AbstractStrategy abstractStrategy;
|
||||||
Canvas canv;
|
Canvas canv;
|
||||||
@ -18,11 +20,14 @@ public class FormTrain{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FormTrain(){
|
public FormTrain(){
|
||||||
|
SelectedTrain = null;
|
||||||
JFrame w=new JFrame ("Loco");
|
JFrame w=new JFrame ("Loco");
|
||||||
JButton buttonCreate = new JButton("create");
|
JButton buttonCreate = new JButton("create");
|
||||||
JButton buttonCreateLocomotive = new JButton("createLocomotive");
|
JButton buttonCreateLocomotive = new JButton("create locomotive");
|
||||||
JButton buttonStrategysStep = new JButton("strategys step");
|
JButton buttonStrategysStep = new JButton("strategys step");
|
||||||
JComboBox comboBoxStrategy = new JComboBox(
|
JButton buttonSelectTrain = new JButton("select train");
|
||||||
|
|
||||||
|
JComboBox<String> comboBoxStrategy = new JComboBox<String>(
|
||||||
new String[]{
|
new String[]{
|
||||||
"к центру",
|
"к центру",
|
||||||
"к краю",
|
"к краю",
|
||||||
@ -51,6 +56,15 @@ public class FormTrain{
|
|||||||
right.setContentAreaFilled(false);
|
right.setContentAreaFilled(false);
|
||||||
right.setName("right");
|
right.setName("right");
|
||||||
right.setIcon(new ImageIcon("D:\\Coffee\\PIbd-21_Kouvshinoff_T._A._WarmlyLocomotive._Harder\\laba1Loco\\images\\arowR340x259.png"));
|
right.setIcon(new ImageIcon("D:\\Coffee\\PIbd-21_Kouvshinoff_T._A._WarmlyLocomotive._Harder\\laba1Loco\\images\\arowR340x259.png"));
|
||||||
|
buttonSelectTrain.addActionListener(
|
||||||
|
new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e){
|
||||||
|
SelectedTrain = _drawingTrain;
|
||||||
|
DialogResult = true;
|
||||||
|
w.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
buttonStrategysStep.addActionListener(
|
buttonStrategysStep.addActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
@ -100,12 +114,26 @@ public class FormTrain{
|
|||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
System.out.println(e.getActionCommand());
|
System.out.println(e.getActionCommand());
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||||
|
// Вызываем диалоговое окно выбора цвета
|
||||||
|
Color selectedColor = JColorChooser.showDialog(w, "Выберите цвет", Color.WHITE);
|
||||||
|
if (selectedColor != null)
|
||||||
|
{
|
||||||
|
color = selectedColor;
|
||||||
|
}
|
||||||
|
Color color2 = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||||
|
// Вызываем диалоговое окно выбора цвета
|
||||||
|
selectedColor = JColorChooser.showDialog(w, "Выберите цвет", Color.WHITE);
|
||||||
|
if (selectedColor != null)
|
||||||
|
{
|
||||||
|
color2 = selectedColor;
|
||||||
|
}
|
||||||
_drawingTrain = new DrawingLoco(
|
_drawingTrain = new DrawingLoco(
|
||||||
random.nextInt(100, 300),
|
random.nextInt(100, 300),
|
||||||
random.nextInt(1000, 3000),
|
random.nextInt(1000, 3000),
|
||||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
color,
|
||||||
random.nextInt(2, 5),
|
random.nextInt(2, 5),
|
||||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
color2,
|
||||||
random.nextInt(0, 2) == 1,
|
random.nextInt(0, 2) == 1,
|
||||||
random.nextInt(0, 2) == 1,
|
random.nextInt(0, 2) == 1,
|
||||||
random.nextInt(0, 2) == 1,
|
random.nextInt(0, 2) == 1,
|
||||||
@ -122,10 +150,17 @@ public class FormTrain{
|
|||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
System.out.println(e.getActionCommand());
|
System.out.println(e.getActionCommand());
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
||||||
|
// Вызываем диалоговое окно выбора цвета
|
||||||
|
Color selectedColor = JColorChooser.showDialog(w, "Выберите цвет", Color.WHITE);
|
||||||
|
if (selectedColor != null)
|
||||||
|
{
|
||||||
|
color = selectedColor;
|
||||||
|
}
|
||||||
_drawingTrain = new DrawingTrain(
|
_drawingTrain = new DrawingTrain(
|
||||||
random.nextInt(100, 300),
|
random.nextInt(100, 300),
|
||||||
random.nextInt(1000, 3000),
|
random.nextInt(1000, 3000),
|
||||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
color,
|
||||||
random.nextInt(2, 5),
|
random.nextInt(2, 5),
|
||||||
pictureBoxWidth,
|
pictureBoxWidth,
|
||||||
pictureBoxHeight);
|
pictureBoxHeight);
|
||||||
@ -177,6 +212,8 @@ public class FormTrain{
|
|||||||
right.setBounds(940, 520, 40, 40);
|
right.setBounds(940, 520, 40, 40);
|
||||||
comboBoxStrategy.setBounds(pictureBoxWidth - 150, 20, 150, 20);
|
comboBoxStrategy.setBounds(pictureBoxWidth - 150, 20, 150, 20);
|
||||||
buttonStrategysStep.setBounds(pictureBoxWidth - 150, 45, 150, 20);
|
buttonStrategysStep.setBounds(pictureBoxWidth - 150, 45, 150, 20);
|
||||||
|
buttonSelectTrain.setBounds(pictureBoxWidth/2, 540, 150, 20);
|
||||||
|
w.add(buttonSelectTrain);
|
||||||
w.add(canv);
|
w.add(canv);
|
||||||
w.add(buttonCreate);
|
w.add(buttonCreate);
|
||||||
w.add(buttonCreateLocomotive);
|
w.add(buttonCreateLocomotive);
|
||||||
@ -186,6 +223,7 @@ public class FormTrain{
|
|||||||
w.add(right);
|
w.add(right);
|
||||||
w.add(comboBoxStrategy);
|
w.add(comboBoxStrategy);
|
||||||
w.add(buttonStrategysStep);
|
w.add(buttonStrategysStep);
|
||||||
|
w.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Canvas extends JComponent{
|
class Canvas extends JComponent{
|
||||||
|
Loading…
Reference in New Issue
Block a user