Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. import java.awt.EventQueue;
  2. import java.awt.Graphics;
  3. import java.awt.Image;
  4. import java.io.File;
  5. import java.io.IOException;
  6.  
  7. import javax.imageio.ImageIO;
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10. import javax.swing.border.EmptyBorder;
  11.  
  12. import javax.swing.DefaultComboBoxModel;
  13. import javax.swing.JComboBox;
  14. import javax.swing.JLabel;
  15. import java.awt.Color;
  16. import java.awt.Font;
  17. import javax.swing.JButton;
  18. import javax.swing.ImageIcon;
  19. import java.awt.event.ActionListener;
  20. import java.awt.event.MouseEvent;
  21. import java.awt.event.MouseListener;
  22. import java.awt.event.ActionEvent;
  23. import javax.swing.JTextField;
  24. import javax.swing.Timer;
  25.  
  26. public class JavaReactor extends JFrame {
  27.  
  28. private JPanel contentPane;
  29.  
  30. /**
  31. * Launch the application.
  32. */
  33. public static void main(String[] args) {
  34. EventQueue.invokeLater(new Runnable() {
  35. public void run() {
  36. try {
  37. JavaReactor frame = new JavaReactor();
  38. frame.setVisible(true);
  39. frame.setResizable(false);
  40. } catch (Exception e) {
  41. e.printStackTrace();
  42. }
  43. }
  44. });
  45. }
  46.  
  47.  
  48. public int i;
  49. private JTextField textField;
  50. private JTextField textField_1;
  51. public int Heat_reactor = 10;
  52. public int Energy_reactor = 0;
  53. public JComboBox comboBox;
  54. public int getIndex;
  55.  
  56. public JavaReactor() {
  57.  
  58. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  59. setBounds(100, 0, 1200, 878);
  60. contentPane = new GameGraphicsAndDigitalOperations();
  61. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  62. setContentPane(contentPane);
  63. contentPane.setLayout(null);
  64.  
  65. GameGraphicsAndDigitalOperations GGADO = new GameGraphicsAndDigitalOperations();
  66.  
  67. comboBox = new JComboBox();
  68. comboBox.setFont(new Font("standard 09_66", Font.PLAIN, 11));
  69. comboBox.setForeground(Color.BLACK);
  70. comboBox.setBackground(Color.LIGHT_GRAY);
  71. comboBox.setBounds(934, 26, 240, 20);
  72. comboBox.addActionListener(new ActionListener() {
  73. public void actionPerformed(ActionEvent e) {
  74. getIndex = comboBox.getSelectedIndex();
  75. System.out.println(getIndex+" "+e);
  76. }});
  77. comboBox.setModel(new DefaultComboBoxModel(GGADO.aBuy));
  78. contentPane.add(comboBox);
  79.  
  80. JLabel lblBay = new JLabel("Buy:");
  81. lblBay.setIcon(new ImageIcon("C:\Users\u0412u043Bu0430u0434u0438u043A\Desktop\Make reactor java IMG\Buy.png"));
  82. lblBay.setFont(new Font("standard 09_66", Font.PLAIN, 11));
  83. lblBay.setBounds(849, 13, 130, 46);
  84. contentPane.add(lblBay);
  85.  
  86. JLabel lblE = new JLabel("Energy:");
  87. lblE.setFont(new Font("standard 09_66", Font.PLAIN, 11));
  88. lblE.setBounds(849, 814, 95, 14);
  89. contentPane.add(lblE);
  90.  
  91. textField_1 = new JTextField();
  92. textField_1.setEditable(false);
  93. textField_1.setBounds(934, 749, 240, 20);
  94. contentPane.add(textField_1);
  95. textField_1.setColumns(10);
  96.  
  97. textField = new JTextField();
  98. textField.setEditable(false);
  99. textField.setBounds(934, 811, 240, 20);
  100. contentPane.add(textField);
  101. textField.setColumns(10);
  102.  
  103. textField.setText(Integer.toString(Energy_reactor));
  104. textField_1.setText(Integer.toString(Heat_reactor));
  105.  
  106. JButton btnNewButton_1 = new JButton("Heat -1");
  107. btnNewButton_1.addActionListener(new ActionListener() {
  108. public void actionPerformed(ActionEvent arg0) {
  109. if(Heat_reactor!=0)
  110. {
  111. Heat_reactor--;
  112. textField_1.setText(Integer.toString(Heat_reactor));
  113. }
  114. }
  115. });
  116. btnNewButton_1.setFont(new Font("standard 09_66", Font.PLAIN, 11));
  117. btnNewButton_1.setBackground(Color.LIGHT_GRAY);
  118. btnNewButton_1.setBounds(849, 780, 325, 23);
  119. contentPane.add(btnNewButton_1);
  120.  
  121. JLabel lblHeat = new JLabel("Heat:");
  122. lblHeat.setFont(new Font("standard 09_66", Font.PLAIN, 11));
  123. lblHeat.setBounds(849, 755, 95, 14);
  124. contentPane.add(lblHeat);
  125. /*Timer t = new Timer(1500,new ActionListener(){public void actionPerformed(ActionEvent e)
  126. {*/
  127. //System.out.println(getIndex);
  128. //getIndex = comboBox.getSelectedIndex();
  129. /*}});*/
  130. //t.start();
  131. }
  132. public int gi()
  133. {
  134. return getIndex;
  135. }
  136. }
  137. class GameGraphicsAndDigitalOperations extends JPanel
  138. {
  139. public String[] aBuy = {"Heat exchanger 50$","Heat inlet 200$","Heat outlet 200$","Heat vent 50$","Reactor rod Uranus 5$"};
  140. public int CombotBoxGetSelect;
  141. public int XDRAWPOLE = 1;
  142. public int YDRAWPOLE = 1;
  143. public int getI;
  144. Boolean b=false;
  145. public GameGraphicsAndDigitalOperations()
  146. {
  147. addMouseListener(new myMouse1());
  148. }
  149. public void paintComponent(Graphics g)
  150. {
  151. Image f = null;
  152. try{f = ImageIO.read(new File("C:\Users\Владик\Desktop\Make reactor java IMG\Pole.png"));}
  153. catch(IOException ex){}
  154. g.drawImage(f,1,1,null);
  155. while(XDRAWPOLE<=20)
  156. {
  157. g.drawImage(f,XDRAWPOLE*40,1,null);
  158. XDRAWPOLE++;
  159. }
  160. XDRAWPOLE = 1;
  161. while(YDRAWPOLE<=20)
  162. {
  163. g.drawImage(f,1,YDRAWPOLE*40,null);
  164. while(XDRAWPOLE<=20)
  165. {
  166. g.drawImage(f,XDRAWPOLE*40,YDRAWPOLE*40,null);
  167. XDRAWPOLE++;
  168. }
  169. XDRAWPOLE = 1;
  170. YDRAWPOLE++;
  171. }
  172. YDRAWPOLE = 1;
  173. try{f = ImageIO.read(new File("C:\Users\Владик\Desktop\Make reactor java IMG\Heat_vent_1.png"));}
  174. catch(IOException ex){}
  175. if(b)
  176. {
  177. g.drawImage(f,5,5,32,32,null);
  178. }
  179. }
  180. public class myMouse1 implements MouseListener
  181. {
  182. public void mouseClicked(MouseEvent e)
  183. {
  184.  
  185. }
  186.  
  187. public void mouseEntered(MouseEvent e)
  188. {
  189.  
  190. }
  191.  
  192. public void mouseExited(MouseEvent e)
  193. {
  194.  
  195. }
  196.  
  197. public void mousePressed(MouseEvent e)
  198. {
  199. JavaReactor Per = new JavaReactor();
  200. getI = Per.getIndex;
  201. int tX = e.getX();
  202. int tY = e.getY();
  203. int col = e.getClickCount();
  204. int btn = e.getButton();
  205. Per.repaint();
  206. System.out.println(Per.comboBox.getSelectedItem());
  207. if((tX>=1)&&(tX<=40)&&(tY>=1)&&(tY<=40)&&(col==1)&&(btn==1)&&(getI==3))
  208. {
  209. b=true;
  210. repaint();
  211. }
  212. }
  213.  
  214. public void mouseReleased(MouseEvent e)
  215. {
  216.  
  217. }
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement