3_3
This commit is contained in:
parent
20c3c33579
commit
25da58586f
@ -49,7 +49,8 @@ public class FormSPAU extends JFrame {
|
||||
if (drawningSPAU == null) {
|
||||
return;
|
||||
}
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage bmp = new BufferedImage(pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight(),
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gr = bmp.createGraphics();
|
||||
drawningSPAU.DrawTransport(gr);
|
||||
ImageIcon imageIcon = new ImageIcon(bmp);
|
||||
@ -105,9 +106,9 @@ public class FormSPAU extends JFrame {
|
||||
mainPanel.add(buttonStep);
|
||||
buttonStep.setBounds(794, 55, 76, 30);
|
||||
buttonStep.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonStep_Click(e);
|
||||
}
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
buttonStep_Click(e);
|
||||
}
|
||||
});
|
||||
|
||||
// ButtonSelectSPAU
|
||||
@ -116,14 +117,14 @@ public class FormSPAU extends JFrame {
|
||||
buttonSelectSPAU.setLocation(new Point(759, 90));
|
||||
buttonSelectSPAU.setBounds(794, 85, 76, 30);
|
||||
buttonSelectSPAU.addActionListener(e -> buttonSelectSPAU_Click(e));
|
||||
|
||||
|
||||
// comboBoxRoll
|
||||
|
||||
|
||||
comboBoxRoll = new JComboBox<>();
|
||||
mainPanel.add(comboBoxRoll);
|
||||
comboBoxRoll.setModel(new DefaultComboBoxModel<>(new String[] { "1", "2", "3" }));
|
||||
comboBoxRoll.setBounds(767, 232, 103, 28);
|
||||
|
||||
|
||||
// comboBoxStrategy
|
||||
comboBoxStrategy = new JComboBox<>();
|
||||
mainPanel.add(comboBoxStrategy);
|
||||
@ -132,7 +133,7 @@ public class FormSPAU extends JFrame {
|
||||
|
||||
buttonUp.setBounds(804, 336, 30, 30);
|
||||
mainPanel.add(buttonUp);
|
||||
ImageIcon iconUp = new ImageIcon("Arrows/upper-arrow.png");
|
||||
ImageIcon iconUp = new ImageIcon("/Arrows/upper-arrow.png");
|
||||
buttonUp.setIcon(iconUp);
|
||||
buttonUp.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -142,7 +143,7 @@ public class FormSPAU extends JFrame {
|
||||
|
||||
buttonDown.setBounds(804, 409, 30, 30);
|
||||
mainPanel.add(buttonDown);
|
||||
ImageIcon iconDown = new ImageIcon("Arrows/down-arrow.png");
|
||||
ImageIcon iconDown = new ImageIcon("/Arrows/down-arrow.png");
|
||||
buttonDown.setIcon(iconDown);
|
||||
buttonDown.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -152,7 +153,7 @@ public class FormSPAU extends JFrame {
|
||||
|
||||
buttonLeft.setBounds(768, 372, 30, 30);
|
||||
mainPanel.add(buttonLeft);
|
||||
ImageIcon iconLeft = new ImageIcon("Arrows/left-arrow.png");
|
||||
ImageIcon iconLeft = new ImageIcon("/Arrows/left-arrow.png");
|
||||
buttonLeft.setIcon(iconLeft);
|
||||
buttonLeft.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -162,7 +163,7 @@ public class FormSPAU extends JFrame {
|
||||
|
||||
buttonRight.setBounds(840, 372, 30, 30);
|
||||
mainPanel.add(buttonRight);
|
||||
ImageIcon iconRight = new ImageIcon("Arrows/right-arrow.png");
|
||||
ImageIcon iconRight = new ImageIcon("/Arrows/right-arrow.png");
|
||||
buttonRight.setIcon(iconRight);
|
||||
buttonRight.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -188,12 +189,25 @@ public class FormSPAU extends JFrame {
|
||||
|
||||
if (wheelCount > 0) {
|
||||
Random random = new Random();
|
||||
drawningSPAU = new DrawningSPAUchild(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()), random.nextInt(200) + 100,
|
||||
(double) random.nextInt(2000) + 1000,
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
true, true,
|
||||
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
Color dopColor = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
|
||||
Color selectedColor = JColorChooser.showDialog(null, "Выберите цвет", color);
|
||||
if (selectedColor != null) {
|
||||
color = selectedColor;
|
||||
}
|
||||
|
||||
Color selectedDopColor = JColorChooser.showDialog(null, "Выберите дополнительный цвет", dopColor);
|
||||
if (selectedDopColor != null) {
|
||||
dopColor = selectedDopColor;
|
||||
}
|
||||
drawningSPAU = new DrawningSPAUchild(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()),
|
||||
random.nextInt(200) + 100,
|
||||
(double) random.nextInt(2000) + 1000,
|
||||
color,
|
||||
dopColor,
|
||||
true, true,
|
||||
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
drawningSPAU.SetPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
|
||||
Draw();
|
||||
}
|
||||
@ -209,10 +223,17 @@ public class FormSPAU extends JFrame {
|
||||
|
||||
if (wheelCount > 0) {
|
||||
Random random = new Random();
|
||||
drawningSPAU = new DrawningSPAU(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()), random.nextInt(200) + 100,
|
||||
(double) random.nextInt(2000) + 1000,
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
Color color = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
|
||||
|
||||
Color selectedColor = JColorChooser.showDialog(null, "Выберите цвет", color);
|
||||
if (selectedColor != null) {
|
||||
color = selectedColor;
|
||||
}
|
||||
drawningSPAU = new DrawningSPAU(wheelCount, Integer.parseInt((String) comboBoxRoll.getSelectedItem()),
|
||||
random.nextInt(200) + 100,
|
||||
(double) random.nextInt(2000) + 1000,
|
||||
color,
|
||||
pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
drawningSPAU.SetPosition(random.nextInt(90) + 20, random.nextInt(90) + 20);
|
||||
Draw();
|
||||
}
|
||||
@ -220,49 +241,45 @@ public class FormSPAU extends JFrame {
|
||||
|
||||
private void buttonSelectSPAU_Click(ActionEvent e) {
|
||||
SelectedSPAU = drawningSPAU;
|
||||
//DialogResult = DialogResult.OK;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int result = JOptionPane.showConfirmDialog(null, "Добавить?", "Add SPAU", JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.OK_OPTION) {
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected void buttonStep_Click (ActionEvent e) {
|
||||
protected void buttonStep_Click(ActionEvent e) {
|
||||
if (drawningSPAU == null) {
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
int selectedIndex = comboBoxStrategy.getSelectedIndex();
|
||||
switch (selectedIndex) {
|
||||
case 0:
|
||||
abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
abstractStrategy = null;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.isEnabled()) {
|
||||
int selectedIndex = comboBoxStrategy.getSelectedIndex();
|
||||
switch (selectedIndex) {
|
||||
case 0:
|
||||
abstractStrategy = new MoveToCenter();
|
||||
break;
|
||||
case 1:
|
||||
abstractStrategy = new MoveToBorder();
|
||||
break;
|
||||
default:
|
||||
abstractStrategy = null;
|
||||
break;
|
||||
}
|
||||
if (abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
abstractStrategy.setData(new DrawningObjectSPAU(drawningSPAU), pictureBoxSPAU.getWidth(),
|
||||
pictureBoxSPAU.getHeight());
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
abstractStrategy.setData(new DrawningObjectSPAU(drawningSPAU), pictureBoxSPAU.getWidth(), pictureBoxSPAU.getHeight());
|
||||
comboBoxStrategy.setEnabled(false);
|
||||
}
|
||||
if (abstractStrategy == null) {
|
||||
return;
|
||||
}
|
||||
abstractStrategy.makeStep();
|
||||
Draw();
|
||||
if (abstractStrategy.getStatus() == Status.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
abstractStrategy = null;
|
||||
}
|
||||
abstractStrategy.makeStep();
|
||||
Draw();
|
||||
if (abstractStrategy.getStatus() == Status.Finish) {
|
||||
comboBoxStrategy.setEnabled(true);
|
||||
abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void buttonMoveActionPerformed(Object sender, ActionEvent e) {
|
||||
|
@ -6,9 +6,10 @@ import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
|
||||
import SelfPropelledArtilleryUnit.Generics.SPAUGenericCollection;
|
||||
import SelfPropelledArtilleryUnit.MovementStrategy.DrawningObjectSPAU;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
public class FormSPAUCollection extends JFrame {
|
||||
private JPanel contentPane;
|
||||
@ -18,7 +19,7 @@ public class FormSPAUCollection extends JFrame {
|
||||
private JButton ButtonRemoveSPAU;
|
||||
private JButton ButtonRefreshCollection;
|
||||
|
||||
private final int countPlaces = 11;
|
||||
private final int countPlaces = 12;
|
||||
private final SPAUGenericCollection<DrawningSPAU, DrawningObjectSPAU> _SPAUs;
|
||||
|
||||
public FormSPAUCollection() {
|
||||
@ -73,24 +74,34 @@ public class FormSPAUCollection extends JFrame {
|
||||
|
||||
setContentPane(contentPane);
|
||||
}
|
||||
|
||||
private void ButtonAddSPAU_Click(ActionEvent e) {
|
||||
FormSPAU form = new FormSPAU();
|
||||
/*
|
||||
if (form.showDialog() == JOptionPane.OK_OPTION) {
|
||||
int addedIndex = _SPAUs.add(form.GetSelectedSPAU());
|
||||
if (addedIndex != -1 && addedIndex <= countPlaces) {
|
||||
JOptionPane.showMessageDialog(this, "Объект добавлен");
|
||||
pictureBoxCollection.setIcon(new ImageIcon(_SPAUs.showSPAUs()));
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(this, "Не удалось добавить объект");
|
||||
form.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
int addedIndex = _SPAUs.add(form.GetSelectedSPAU());
|
||||
if (addedIndex != -1 && addedIndex <= countPlaces) {
|
||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||
ImageIcon iconSPAU = new ImageIcon(_SPAUs.showSPAUs());
|
||||
pictureBoxCollection.setIcon(iconSPAU);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(contentPane, "Не удалось добавить объект");
|
||||
}
|
||||
form.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
int result = JOptionPane.showConfirmDialog(null, "Add SPAU?", "Add SPAU", JOptionPane.OK_CANCEL_OPTION);
|
||||
|
||||
if (result == JOptionPane.OK_OPTION) {
|
||||
form.setSize(900, 500);
|
||||
form.setVisible(true);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
private void ButtonRemoveSPAU_Click(ActionEvent e) {
|
||||
if (JOptionPane.showConfirmDialog(this, "Удалить объект?", "Удаление", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
if (JOptionPane.showConfirmDialog(this, "Удалить объект?", "Удаление",
|
||||
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
int pos;
|
||||
try {
|
||||
pos = Integer.parseInt(maskedTextBoxNumber.getText());
|
||||
@ -110,18 +121,4 @@ public class FormSPAUCollection extends JFrame {
|
||||
private void ButtonRefreshCollection_Click(ActionEvent e) {
|
||||
pictureBoxCollection.setIcon(new ImageIcon(_SPAUs.showSPAUs()));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
FormSPAUCollection frame = new FormSPAUCollection();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,8 @@ public class SPAUGenericCollection<T extends DrawningSPAU, U extends IMoveableOb
|
||||
}
|
||||
|
||||
private void drawBackground(Graphics g) {
|
||||
g.setColor(Color.WHITE);
|
||||
g.fillRect(0, 0, _pictureWidth, _pictureHeight); // заполняем весь прямоугольник белым цветом
|
||||
g.setColor(Color.BLACK);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) {
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) {
|
||||
@ -76,6 +78,7 @@ public class SPAUGenericCollection<T extends DrawningSPAU, U extends IMoveableOb
|
||||
stringCount = 0;
|
||||
}
|
||||
current.DrawTransport(g);
|
||||
System.out.print(i + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package SelfPropelledArtilleryUnit.Generics;
|
||||
public class SetGeneric<T> {
|
||||
private final T[] places;
|
||||
public int count;
|
||||
public int size = 0;
|
||||
|
||||
public SetGeneric(int count) {
|
||||
this.count = count;
|
||||
@ -14,7 +15,7 @@ public class SetGeneric<T> {
|
||||
}
|
||||
|
||||
public int size(){
|
||||
return count;
|
||||
return size;
|
||||
}
|
||||
|
||||
public int insert(T spau, int position) {
|
||||
@ -40,6 +41,7 @@ public class SetGeneric<T> {
|
||||
places[i] = places[i - 1];
|
||||
}
|
||||
places[position] = spau;
|
||||
size++;
|
||||
return position;
|
||||
}
|
||||
|
||||
@ -48,6 +50,7 @@ public class SetGeneric<T> {
|
||||
return false;
|
||||
|
||||
places[position] = null;
|
||||
size--;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user