Третья лабораторная работа.
This commit is contained in:
parent
e7c253b1c7
commit
0d9c3714a7
@ -1,15 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
<Property name="title" type="java.lang.String" value="Бомбардировщик"/>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Arial" size="10" style="0"/>
|
||||
</Property>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[700, 400]"/>
|
||||
</Property>
|
||||
<Property name="size" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[700, 400]"/>
|
||||
</Property>
|
||||
@ -50,6 +47,8 @@
|
||||
<Component id="createAirBomberButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="ModifyButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="buttonSelect" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace pref="157" max="32767" attributes="0"/>
|
||||
@ -86,8 +85,9 @@
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="createAirBomberButton" pref="31" max="32767" attributes="0"/>
|
||||
<Component id="ModifyButton" max="32767" attributes="0"/>
|
||||
<Component id="createAirBomberButton" max="32767" attributes="0"/>
|
||||
<Component id="buttonSelect" alignment="0" pref="31" max="32767" attributes="0"/>
|
||||
<Component id="ModifyButton" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
@ -267,5 +267,13 @@
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonSelect">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Выбрать"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonSelectActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -5,23 +5,26 @@
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.JOptionPane;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
public class JFrameAirBomber extends javax.swing.JDialog {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameAirBomber
|
||||
*/
|
||||
public JFrameAirBomber() {
|
||||
public JFrameAirBomber(JFrame parent) {
|
||||
super(parent, "Бомбардировщик", true);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private DrawingAirBomber _airBomber;
|
||||
private EnginesType enginesType = EnginesType.RECTANGLE;
|
||||
private DrawingAirBomber _airBomberResult;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
@ -44,11 +47,11 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
ModifyButton = new javax.swing.JButton();
|
||||
jLabelEngines1 = new javax.swing.JLabel();
|
||||
jComboBoxEnginesType = new javax.swing.JComboBox<>();
|
||||
buttonSelect = new javax.swing.JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle("Бомбардировщик");
|
||||
setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
|
||||
setPreferredSize(new java.awt.Dimension(700, 400));
|
||||
setSize(new java.awt.Dimension(700, 400));
|
||||
|
||||
createAirBomberButton.setText("Создать");
|
||||
@ -135,6 +138,13 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
buttonSelect.setText("Выбрать");
|
||||
buttonSelect.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonSelectActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
@ -154,7 +164,9 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(createAirBomberButton)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(ModifyButton)))
|
||||
.addComponent(ModifyButton)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(buttonSelect)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 157, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
@ -183,7 +195,8 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
.addComponent(jComboBoxEnginesType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonSelect, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
|
||||
.addComponent(ModifyButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
@ -201,7 +214,9 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
|
||||
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
|
||||
Random rnd = new Random();
|
||||
_airBomber = new DrawingAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), (jComboBoxEngines.getSelectedIndex() + 1) * 2, enginesType);
|
||||
Color chosenColor = JColorChooser.showDialog(this, "Вибирете цвет", Color.BLACK);
|
||||
_airBomber = new DrawingAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), chosenColor, (jComboBoxEngines.getSelectedIndex() + 1) * 2, enginesType);
|
||||
SetData();
|
||||
Draw();
|
||||
}//GEN-LAST:event_createAirBomberButtonActionPerformed
|
||||
|
||||
@ -233,11 +248,13 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
|
||||
private void ModifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ModifyButtonActionPerformed
|
||||
Random rnd = new Random();
|
||||
Color chosenColor = JColorChooser.showDialog(this, "Вибирете цвет", Color.BLACK);
|
||||
Color chosenDopColor = JColorChooser.showDialog(this, "Вибирете цвет", Color.BLACK);
|
||||
_airBomber = new DrawingHeavyAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
chosenColor,
|
||||
(jComboBoxEngines.getSelectedIndex() + 1) * 2,
|
||||
enginesType,
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
chosenDopColor,
|
||||
rnd.nextBoolean(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
Draw();
|
||||
@ -258,6 +275,11 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
}
|
||||
}//GEN-LAST:event_jComboBoxEnginesTypeItemStateChanged
|
||||
|
||||
private void buttonSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSelectActionPerformed
|
||||
_airBomberResult = _airBomber;
|
||||
dispose();
|
||||
}//GEN-LAST:event_buttonSelectActionPerformed
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
@ -270,6 +292,11 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
airBomberCanvas.repaint();
|
||||
}
|
||||
|
||||
public DrawingAirBomber run(){
|
||||
setVisible(true);
|
||||
return _airBomberResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
@ -300,7 +327,7 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrameMap().setVisible(true);
|
||||
new JFrameDopGenerics().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -308,6 +335,7 @@ public class JFrameAirBomber extends javax.swing.JFrame {
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton ModifyButton;
|
||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||
private javax.swing.JButton buttonSelect;
|
||||
private javax.swing.JButton createAirBomberButton;
|
||||
private javax.swing.JButton downButton;
|
||||
private javax.swing.JComboBox<String> jComboBoxEngines;
|
||||
|
171
AirBomber/src/AirBomberPackage/JFrameDopGenerics.form
Normal file
171
AirBomber/src/AirBomberPackage/JFrameDopGenerics.form
Normal file
@ -0,0 +1,171 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Бомбардировщик"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="createAirBomberButton" pref="569" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="upButton" alignment="1" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="leftButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="downButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" pref="30" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="airBomberCanvas" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="airBomberCanvas" pref="327" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="createAirBomberButton" min="-2" pref="68" max="-2" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="upButton" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="leftButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="downButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<Component id="rightButton" alignment="3" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="createAirBomberButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Создать"/>
|
||||
<Property name="name" type="java.lang.String" value="createAirBomberButton" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="createAirBomberButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="leftButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowLeft.png"/>
|
||||
</Property>
|
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
|
||||
<Insets value="[0, 0, 0, 0]"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonLeft" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="downButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowDown.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonDown" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="rightButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowRight.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonRight" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="upButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowUp.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonUp" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="AirBomberPackage.CanvasMy" name="airBomberCanvas">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
261
AirBomber/src/AirBomberPackage/JFrameDopGenerics.java
Normal file
261
AirBomber/src/AirBomberPackage/JFrameDopGenerics.java
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
import java.util.Random;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class JFrameDopGenerics extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameDopGenerics
|
||||
*/
|
||||
public JFrameDopGenerics() {
|
||||
initComponents();
|
||||
int numOfDecals = 2;
|
||||
airBomberGenerator = new SetAirBombersGenericDop<>(numOfDecals);
|
||||
Random rnd = new Random(System.currentTimeMillis());
|
||||
for (int i = 0; i < numOfDecals; i++){
|
||||
EntityAirBomber airBomber;
|
||||
int rndNum = rnd.nextInt(0, 100);
|
||||
if (rndNum % 2 == 0){
|
||||
//создаём обычный бомбардировщик
|
||||
airBomber = new EntityAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)));
|
||||
}
|
||||
else{
|
||||
//создаём тяжелый бомбардировщик
|
||||
airBomber = new EntityHeavyAirBomber(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
new Color(rnd.nextInt(0, 256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)),
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean(),
|
||||
rnd.nextBoolean());
|
||||
}
|
||||
airBomberGenerator.add(airBomber);
|
||||
}
|
||||
|
||||
for (int i = 0; i < numOfDecals; i++){
|
||||
int rndNum = rnd.nextInt(0, 500);
|
||||
IDrawingObjectDop engines = null;
|
||||
if (rndNum % 3 == 0){
|
||||
//создаем квадратные двигатели
|
||||
engines = new DrawingEngines();
|
||||
}
|
||||
else if (rndNum % 3 == 1){
|
||||
//создаём треугольные двигатели
|
||||
engines = new DrawingEnginesTriangle();
|
||||
}
|
||||
else {
|
||||
//создаём круглые двигатели
|
||||
engines = new DrawingEnginesOval();
|
||||
}
|
||||
engines.setNumberOfEngines(rnd.nextInt(1,4) * 2);
|
||||
airBomberGenerator.add(engines);
|
||||
}
|
||||
}
|
||||
|
||||
private DrawingAirBomber _airBomber;
|
||||
private SetAirBombersGenericDop<EntityAirBomber, IDrawingObjectDop> airBomberGenerator;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
createAirBomberButton = new javax.swing.JButton();
|
||||
leftButton = new javax.swing.JButton();
|
||||
downButton = new javax.swing.JButton();
|
||||
rightButton = new javax.swing.JButton();
|
||||
upButton = new javax.swing.JButton();
|
||||
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
setTitle("Бомбардировщик");
|
||||
|
||||
createAirBomberButton.setText("Создать");
|
||||
createAirBomberButton.setName("createAirBomberButton"); // NOI18N
|
||||
createAirBomberButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
createAirBomberButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
|
||||
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
|
||||
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setName("buttonLeft"); // NOI18N
|
||||
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
|
||||
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setName("buttonDown"); // NOI18N
|
||||
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
downButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
|
||||
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setName("buttonRight"); // NOI18N
|
||||
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
|
||||
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setName("buttonUp"); // NOI18N
|
||||
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
upButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
|
||||
.addGap(18, 18, 18)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(17, 17, 17))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(createAirBomberButton, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void createAirBomberButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAirBomberButtonActionPerformed
|
||||
_airBomber = airBomberGenerator.buildAirBomber();
|
||||
SetData();
|
||||
Draw();
|
||||
}//GEN-LAST:event_createAirBomberButtonActionPerformed
|
||||
|
||||
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
||||
if (_airBomber == null) return;
|
||||
String name = ((JButton) evt.getSource()).getName();
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_airBomber.MoveTransport(Direction.UP);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_airBomber.MoveTransport(Direction.DOWN);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_airBomber.MoveTransport(Direction.LEFT);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_airBomber.MoveTransport(Direction.RIGHT);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}//GEN-LAST:event_moveButtonActionPerformed
|
||||
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
_airBomber.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), airBomberCanvas.getWidth(), airBomberCanvas.getHeight());
|
||||
airBomberCanvas.setAirBomber(_airBomber);
|
||||
}
|
||||
|
||||
private void Draw(){
|
||||
airBomberCanvas.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameDopGenerics.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrameDopGenerics().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||
private javax.swing.JButton createAirBomberButton;
|
||||
private javax.swing.JButton downButton;
|
||||
private javax.swing.JButton leftButton;
|
||||
private javax.swing.JButton rightButton;
|
||||
private javax.swing.JButton upButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
247
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.form
Normal file
247
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.form
Normal file
@ -0,0 +1,247 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="airBomberCanvas" min="-2" pref="664" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="25" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="comboBoxSelectorMap" max="32767" attributes="0"/>
|
||||
<Component id="buttonAddAirBomber" max="32767" attributes="0"/>
|
||||
<Component id="maskedTextBoxPosition" max="32767" attributes="0"/>
|
||||
<Component id="buttonRemoveAirBomber" max="32767" attributes="0"/>
|
||||
<Component id="buttonShowStorage" max="32767" attributes="0"/>
|
||||
<Component id="buttonShowOnMap" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="23" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="leftButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="upButton" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="downButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="62" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="airBomberCanvas" alignment="0" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="comboBoxSelectorMap" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="60" max="-2" attributes="0"/>
|
||||
<Component id="buttonAddAirBomber" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="38" max="-2" attributes="0"/>
|
||||
<Component id="maskedTextBoxPosition" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="buttonRemoveAirBomber" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="96" max="-2" attributes="0"/>
|
||||
<Component id="buttonShowStorage" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="12" max="32767" attributes="0"/>
|
||||
<Component id="buttonShowOnMap" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="108" max="-2" attributes="0"/>
|
||||
<Component id="upButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="downButton" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="leftButton" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="rightButton" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="AirBomberPackage.CanvasMy" name="airBomberCanvas">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
|
||||
<Property name="useNullLayout" type="boolean" value="true"/>
|
||||
</Layout>
|
||||
</Container>
|
||||
<Component class="javax.swing.JComboBox" name="comboBoxSelectorMap">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="Простая карта"/>
|
||||
<StringItem index="1" value="Городская карта"/>
|
||||
<StringItem index="2" value="Линейная карта"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
<Property name="selectedIndex" type="int" value="-1"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="comboBoxSelectorMapItemStateChanged"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonAddAirBomber">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Добавить бомбардировщик"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAddAirBomberActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JFormattedTextField" name="maskedTextBoxPosition">
|
||||
<Properties>
|
||||
<Property name="formatterFactory" type="javax.swing.JFormattedTextField$AbstractFormatterFactory" editor="org.netbeans.modules.form.editors.AbstractFormatterFactoryEditor" preCode="try {" postCode="} catch (java.text.ParseException ex) {
ex.printStackTrace();
}">
|
||||
<Format format="##" subtype="-1" type="5"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonRemoveAirBomber">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Удалить бомбардировщик"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonRemoveAirBomberActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonShowStorage">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Посмотреть хранилище"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonShowStorageActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonShowOnMap">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Посмотреть карту"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonShowOnMapActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="leftButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowLeft.png"/>
|
||||
</Property>
|
||||
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
|
||||
<Insets value="[0, 0, 0, 0]"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonLeft" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="downButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowDown.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonDown" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="rightButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowRight.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonRight" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="upButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/AirBomberPackage/arrowUp.png"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="buttonUp" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[30, 30]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="moveButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Инструменты"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
355
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.java
Normal file
355
AirBomber/src/AirBomberPackage/JFrameMapWithSetAirBombers.java
Normal file
@ -0,0 +1,355 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class JFrameMapWithSetAirBombers extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form JFrameMapWithSetAirBombers
|
||||
*/
|
||||
public JFrameMapWithSetAirBombers() {
|
||||
initComponents();
|
||||
}
|
||||
private MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> _mapAirBombersCollectionGeneric;
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
airBomberCanvas = new AirBomberPackage.CanvasMy();
|
||||
comboBoxSelectorMap = new javax.swing.JComboBox<>();
|
||||
buttonAddAirBomber = new javax.swing.JButton();
|
||||
maskedTextBoxPosition = new javax.swing.JFormattedTextField();
|
||||
buttonRemoveAirBomber = new javax.swing.JButton();
|
||||
buttonShowStorage = new javax.swing.JButton();
|
||||
buttonShowOnMap = new javax.swing.JButton();
|
||||
leftButton = new javax.swing.JButton();
|
||||
downButton = new javax.swing.JButton();
|
||||
rightButton = new javax.swing.JButton();
|
||||
upButton = new javax.swing.JButton();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
comboBoxSelectorMap.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Простая карта", "Городская карта", "Линейная карта" }));
|
||||
comboBoxSelectorMap.setSelectedIndex(-1);
|
||||
comboBoxSelectorMap.addItemListener(new java.awt.event.ItemListener() {
|
||||
public void itemStateChanged(java.awt.event.ItemEvent evt) {
|
||||
comboBoxSelectorMapItemStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonAddAirBomber.setText("Добавить бомбардировщик");
|
||||
buttonAddAirBomber.setToolTipText("");
|
||||
buttonAddAirBomber.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonAddAirBomberActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
maskedTextBoxPosition.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##")));
|
||||
} catch (java.text.ParseException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
buttonRemoveAirBomber.setText("Удалить бомбардировщик");
|
||||
buttonRemoveAirBomber.setToolTipText("");
|
||||
buttonRemoveAirBomber.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonRemoveAirBomberActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonShowStorage.setText("Посмотреть хранилище");
|
||||
buttonShowStorage.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonShowStorageActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonShowOnMap.setText("Посмотреть карту");
|
||||
buttonShowOnMap.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonShowOnMapActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
leftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowLeft.png"))); // NOI18N
|
||||
leftButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
|
||||
leftButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.setName("buttonLeft"); // NOI18N
|
||||
leftButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
leftButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
downButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowDown.png"))); // NOI18N
|
||||
downButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
downButton.setName("buttonDown"); // NOI18N
|
||||
downButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
downButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
rightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowRight.png"))); // NOI18N
|
||||
rightButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.setName("buttonRight"); // NOI18N
|
||||
rightButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
rightButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/AirBomberPackage/arrowUp.png"))); // NOI18N
|
||||
upButton.setMaximumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setMinimumSize(new java.awt.Dimension(30, 30));
|
||||
upButton.setName("buttonUp"); // NOI18N
|
||||
upButton.setPreferredSize(new java.awt.Dimension(30, 30));
|
||||
upButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
moveButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel1.setText("Инструменты");
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.PREFERRED_SIZE, 664, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(comboBoxSelectorMap, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonAddAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(maskedTextBoxPosition)
|
||||
.addComponent(buttonRemoveAirBomber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonShowStorage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonShowOnMap, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addComponent(jLabel1))
|
||||
.addGap(23, 23, 23))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addGap(62, 62, 62))))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(airBomberCanvas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(15, 15, 15)
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(comboBoxSelectorMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(60, 60, 60)
|
||||
.addComponent(buttonAddAirBomber)
|
||||
.addGap(38, 38, 38)
|
||||
.addComponent(maskedTextBoxPosition, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(buttonRemoveAirBomber)
|
||||
.addGap(96, 96, 96)
|
||||
.addComponent(buttonShowStorage)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
|
||||
.addComponent(buttonShowOnMap)
|
||||
.addGap(108, 108, 108)
|
||||
.addComponent(upButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(downButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(leftButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(rightButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void moveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveButtonActionPerformed
|
||||
String name = ((JButton) evt.getSource()).getName();
|
||||
Direction dir = Direction.NONE;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
dir = Direction.UP;
|
||||
break;
|
||||
case "buttonDown":
|
||||
dir = Direction.DOWN;
|
||||
break;
|
||||
case "buttonLeft":
|
||||
dir = Direction.LEFT;
|
||||
break;
|
||||
case "buttonRight":
|
||||
dir = Direction.RIGHT;
|
||||
break;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.MoveObject(dir), 0, 0, null);
|
||||
}//GEN-LAST:event_moveButtonActionPerformed
|
||||
|
||||
private void comboBoxSelectorMapItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboBoxSelectorMapItemStateChanged
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.getSelectedIndex())
|
||||
{
|
||||
case 0:
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case 1:
|
||||
map = new CityMap();
|
||||
break;
|
||||
case 2:
|
||||
map = new LineMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapAirBombersCollectionGeneric = new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(
|
||||
airBomberCanvas.getWidth(), airBomberCanvas.getHeight(), map);
|
||||
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapAirBombersCollectionGeneric = null;
|
||||
}
|
||||
}//GEN-LAST:event_comboBoxSelectorMapItemStateChanged
|
||||
|
||||
private void buttonAddAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddAirBomberActionPerformed
|
||||
if (_mapAirBombersCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
JFrameAirBomber form = new JFrameAirBomber(this);
|
||||
DrawingAirBomber selectedAirBomber = form.run();
|
||||
if (selectedAirBomber != null)
|
||||
{
|
||||
DrawingObjectAirBomber objectAirBomber = new DrawingObjectAirBomber(selectedAirBomber);
|
||||
if (_mapAirBombersCollectionGeneric.add(objectAirBomber) != -1)
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, "Объект добавлен");
|
||||
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(this, "Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}//GEN-LAST:event_buttonAddAirBomberActionPerformed
|
||||
|
||||
private void buttonRemoveAirBomberActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveAirBomberActionPerformed
|
||||
if (maskedTextBoxPosition.getText().isBlank() || maskedTextBoxPosition.getText().isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
var res = JOptionPane.showConfirmDialog((Component) this, (Object) "Удалить объект?", "Удаление", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (res == JOptionPane.CANCEL_OPTION)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Integer.parseInt(maskedTextBoxPosition.getText());
|
||||
if (_mapAirBombersCollectionGeneric.remove(pos) != null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Объект удален");
|
||||
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,"Не удалось удалить объект!");
|
||||
}
|
||||
}//GEN-LAST:event_buttonRemoveAirBomberActionPerformed
|
||||
|
||||
private void buttonShowStorageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowStorageActionPerformed
|
||||
if (_mapAirBombersCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowSet(), 0, 0, null);
|
||||
}//GEN-LAST:event_buttonShowStorageActionPerformed
|
||||
|
||||
private void buttonShowOnMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowOnMapActionPerformed
|
||||
if (_mapAirBombersCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
airBomberCanvas.getGraphics().drawImage(_mapAirBombersCollectionGeneric.ShowOnMap(), 0, 0, null);
|
||||
}//GEN-LAST:event_buttonShowOnMapActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(JFrameMapWithSetAirBombers.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new JFrameMapWithSetAirBombers().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private AirBomberPackage.CanvasMy airBomberCanvas;
|
||||
private javax.swing.JButton buttonAddAirBomber;
|
||||
private javax.swing.JButton buttonRemoveAirBomber;
|
||||
private javax.swing.JButton buttonShowOnMap;
|
||||
private javax.swing.JButton buttonShowStorage;
|
||||
private javax.swing.JComboBox<String> comboBoxSelectorMap;
|
||||
private javax.swing.JButton downButton;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JButton leftButton;
|
||||
private javax.swing.JFormattedTextField maskedTextBoxPosition;
|
||||
private javax.swing.JButton rightButton;
|
||||
private javax.swing.JButton upButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
123
AirBomber/src/AirBomberPackage/MapWithSetAirBombersGeneric.java
Normal file
123
AirBomber/src/AirBomberPackage/MapWithSetAirBombersGeneric.java
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class MapWithSetAirBombersGeneric <T extends IDrawingObject, U extends AbstractMap> {
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _placeSizeWidth = 110;
|
||||
private int _placeSizeHeight = 100;
|
||||
private SetAirBombersGeneric<T> _setAirBombers;
|
||||
private U _map;
|
||||
public MapWithSetAirBombersGeneric(int picWidth, int picHeight, U map)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_setAirBombers = new SetAirBombersGeneric<T>(width * height);
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public int add(T airBomber){
|
||||
return _setAirBombers.Insert(airBomber);
|
||||
}
|
||||
|
||||
public T remove(int position){
|
||||
return _setAirBombers.Remove(position);
|
||||
}
|
||||
|
||||
public BufferedImage ShowSet()
|
||||
{
|
||||
BufferedImage bmp = new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gr = bmp.createGraphics();
|
||||
DrawBackground(gr);
|
||||
DrawAirBombers(gr);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public BufferedImage ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
{
|
||||
var airBomber = _setAirBombers.Get(i);
|
||||
if (airBomber != null)
|
||||
{
|
||||
return _map.CreateMap(700, 700, airBomber);
|
||||
}
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
public BufferedImage MoveObject(Direction direction)
|
||||
{
|
||||
if (_map != null)
|
||||
{
|
||||
return _map.MoveObject(direction);
|
||||
}
|
||||
return new BufferedImage(_pictureWidth, _pictureHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
private void Shaking()
|
||||
{
|
||||
int j = _setAirBombers.Count - 1;
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
{
|
||||
if (_setAirBombers.Get(i) == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setAirBombers.Get(j);
|
||||
if (car != null)
|
||||
{
|
||||
_setAirBombers.Insert(car, i);
|
||||
_setAirBombers.Remove(j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j <= i)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics2D g)
|
||||
{
|
||||
g.setColor(Color.GRAY);
|
||||
g.fillRect(0, 0, _pictureWidth, _pictureHeight);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setStroke(new BasicStroke(3));
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.drawLine(i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.drawLine(i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
|
||||
}
|
||||
g.setStroke(new BasicStroke(1));
|
||||
g.setColor(Color.BLACK);
|
||||
}
|
||||
|
||||
private void DrawAirBombers(Graphics2D g)
|
||||
{
|
||||
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
{
|
||||
if (_setAirBombers.Get(i) != null){
|
||||
_setAirBombers.Get(i).SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
_setAirBombers.Get(i).DrawingObject(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
AirBomber/src/AirBomberPackage/SetAirBombersGeneric.java
Normal file
100
AirBomber/src/AirBomberPackage/SetAirBombersGeneric.java
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class SetAirBombersGeneric<T> {
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T[] _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetAirBombersGeneric(int count)
|
||||
{
|
||||
_places = (T[]) new Object[count];
|
||||
Count = count;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="airBomber">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airBomber)
|
||||
{
|
||||
return Insert(airBomber, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="airBomber">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T airBomber, int position)
|
||||
{
|
||||
if (position >= _places.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int indexNull = -1;
|
||||
for (int i = position; i < _places.length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
indexNull = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexNull == -1) return -1;
|
||||
for (int i = indexNull; i > position; i--)
|
||||
{
|
||||
T tmp = _places[i];
|
||||
_places[i] = _places[i - 1];
|
||||
_places[i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
_places[position] = airBomber;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= _places.length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
T removedObject = _places[position];
|
||||
_places[position] = null;
|
||||
return removedObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position >= _places.length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
99
AirBomber/src/AirBomberPackage/SetAirBombersGenericDop.java
Normal file
99
AirBomber/src/AirBomberPackage/SetAirBombersGenericDop.java
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package AirBomberPackage;
|
||||
import java.util.Random;
|
||||
/**
|
||||
*
|
||||
* @author Андрей
|
||||
*/
|
||||
public class SetAirBombersGenericDop<T extends EntityAirBomber, U extends IDrawingObjectDop> {
|
||||
private Object[] _bases;
|
||||
private Object[] _engines;
|
||||
private int Count;
|
||||
|
||||
public SetAirBombersGenericDop(int count){
|
||||
_bases = new Object[count];
|
||||
_engines = new Object[count];
|
||||
Count = count;
|
||||
}
|
||||
|
||||
public int add(T base){
|
||||
return add(base, 0);
|
||||
}
|
||||
|
||||
public int add(T base, int position){
|
||||
if (position >= _bases.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_bases[position] != null)
|
||||
{
|
||||
int indexNull = -1;
|
||||
for (int i = position; i < _bases.length; i++)
|
||||
{
|
||||
if (_bases[i] == null)
|
||||
{
|
||||
indexNull = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexNull == -1) return -1;
|
||||
for (int i = indexNull; i > position; i--)
|
||||
{
|
||||
T tmp = (T) _bases[i];
|
||||
_bases[i] = _bases[i - 1];
|
||||
_bases[i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
_bases[position] = base;
|
||||
return position;
|
||||
}
|
||||
|
||||
public int add(U engine){
|
||||
return add(engine, 0);
|
||||
}
|
||||
|
||||
public int add(U engine, int position){
|
||||
if (position >= _engines.length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_engines[position] != null)
|
||||
{
|
||||
int indexNull = -1;
|
||||
for (int i = position; i < _engines.length; i++)
|
||||
{
|
||||
if (_engines[i] == null)
|
||||
{
|
||||
indexNull = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexNull == -1) return -1;
|
||||
for (int i = indexNull; i > position; i--)
|
||||
{
|
||||
U tmp = (U) _engines[i];
|
||||
_engines[i] = _engines[i - 1];
|
||||
_engines[i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
_engines[position] = engine;
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
public DrawingAirBomber buildAirBomber(){
|
||||
Random rnd = new Random();
|
||||
int baseIndex = rnd.nextInt(0, _bases.length);
|
||||
int engineIndex = rnd.nextInt(0, _engines.length);
|
||||
EnginesType enginesType;
|
||||
T selectedBase = (T) _bases[baseIndex];
|
||||
U selectedEngines = (U) _engines[engineIndex];
|
||||
if (selectedEngines instanceof DrawingEngines) enginesType = EnginesType.RECTANGLE;
|
||||
else if (selectedEngines instanceof DrawingEnginesTriangle) enginesType = EnginesType.TRIANGLE;
|
||||
else enginesType = EnginesType.OVAL;
|
||||
return new DrawingAirBomber(selectedBase.getSpeed(), selectedBase.getWeight(), selectedBase.getBodyColor(), selectedEngines.getNumberOfEngines(), enginesType);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user