Advertisement
Reykez

1 / sterowanie lampkami

Feb 18th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.12 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package main;
  7.  
  8. import com.mollin.yapi.*;
  9. import com.mollin.yapi.enumeration.YeelightEffect;
  10. import com.mollin.yapi.enumeration.YeelightFlowAction;
  11. import com.mollin.yapi.flow.YeelightFlow;
  12. import java.awt.KeyEventDispatcher;
  13. import java.awt.KeyboardFocusManager;
  14. import java.awt.event.KeyEvent;
  15. import java.util.logging.Level;
  16. import java.util.logging.LogManager;
  17. import java.util.logging.Logger;
  18. import org.jnativehook.GlobalScreen;
  19. import org.jnativehook.NativeHookException;
  20. import org.jnativehook.keyboard.NativeKeyEvent;
  21. import org.jnativehook.keyboard.NativeKeyListener;
  22. import org.jnativehook.mouse.NativeMouseWheelEvent;
  23. import org.jnativehook.mouse.NativeMouseWheelListener;
  24.  
  25.  
  26. /**
  27. *
  28. * @author Reykez
  29. */
  30. public class Main extends javax.swing.JFrame implements NativeKeyListener, NativeMouseWheelListener{
  31.  
  32. YeelightDevice dv1, dv2, dv3;
  33.  
  34. boolean lampa = false;
  35. int bright=100;
  36. boolean isAltPressed = false;
  37.  
  38. /**
  39. * Creates new form Main
  40. */
  41. public Main() {
  42. try {
  43. dv1 = new YeelightDevice("192.168.8.102", 55443, YeelightEffect.SMOOTH, 500);
  44. dv2 = new YeelightDevice("192.168.8.103", 55443, YeelightEffect.SMOOTH, 500);
  45. dv3 = new YeelightDevice("192.168.8.104", 55443, YeelightEffect.SMOOTH, 500);
  46. } catch(Exception e) { e.printStackTrace(); }
  47. initComponents();
  48. }
  49.  
  50. /**
  51. * This method is called from within the constructor to initialize the form.
  52. * WARNING: Do NOT modify this code. The content of this method is always
  53. * regenerated by the Form Editor.
  54. */
  55. @SuppressWarnings("unchecked")
  56. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  57. private void initComponents() {
  58.  
  59. lgroup = new javax.swing.ButtonGroup();
  60. rgroup = new javax.swing.ButtonGroup();
  61. jPanel1 = new javax.swing.JPanel();
  62. jLabel1 = new javax.swing.JLabel();
  63. jLabel2 = new javax.swing.JLabel();
  64. jRadioButton1 = new javax.swing.JRadioButton();
  65. jRadioButton2 = new javax.swing.JRadioButton();
  66. jRadioButton3 = new javax.swing.JRadioButton();
  67. jRadioButton4 = new javax.swing.JRadioButton();
  68. lr = new javax.swing.JTextField();
  69. lg = new javax.swing.JTextField();
  70. lb = new javax.swing.JTextField();
  71. lt1 = new javax.swing.JRadioButton();
  72. lt2 = new javax.swing.JRadioButton();
  73. lt3 = new javax.swing.JRadioButton();
  74. lt4 = new javax.swing.JRadioButton();
  75. rt1 = new javax.swing.JRadioButton();
  76. rt2 = new javax.swing.JRadioButton();
  77. rt3 = new javax.swing.JRadioButton();
  78. rt4 = new javax.swing.JRadioButton();
  79.  
  80. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  81.  
  82. jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  83.  
  84. jLabel1.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
  85. jLabel1.setText("LAMPA");
  86.  
  87. jLabel2.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
  88. jLabel2.setText("PC");
  89.  
  90. jRadioButton1.setText("ON");
  91. jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
  92. public void actionPerformed(java.awt.event.ActionEvent evt) {
  93. jRadioButton1ActionPerformed(evt);
  94. }
  95. });
  96.  
  97. jRadioButton2.setText("OFF");
  98. jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
  99. public void actionPerformed(java.awt.event.ActionEvent evt) {
  100. jRadioButton2ActionPerformed(evt);
  101. }
  102. });
  103.  
  104. jRadioButton3.setText("ON");
  105. jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
  106. public void actionPerformed(java.awt.event.ActionEvent evt) {
  107. jRadioButton3ActionPerformed(evt);
  108. }
  109. });
  110.  
  111. jRadioButton4.setText("OFF");
  112. jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
  113. public void actionPerformed(java.awt.event.ActionEvent evt) {
  114. jRadioButton4ActionPerformed(evt);
  115. }
  116. });
  117.  
  118. lr.setText("0");
  119. lr.addActionListener(new java.awt.event.ActionListener() {
  120. public void actionPerformed(java.awt.event.ActionEvent evt) {
  121. lrActionPerformed(evt);
  122. }
  123. });
  124.  
  125. lg.setText("0");
  126. lg.addActionListener(new java.awt.event.ActionListener() {
  127. public void actionPerformed(java.awt.event.ActionEvent evt) {
  128. lgActionPerformed(evt);
  129. }
  130. });
  131.  
  132. lb.setText("0");
  133. lb.addActionListener(new java.awt.event.ActionListener() {
  134. public void actionPerformed(java.awt.event.ActionEvent evt) {
  135. lbActionPerformed(evt);
  136. }
  137. });
  138.  
  139. lgroup.add(lt1);
  140. lt1.setText("DEFAULT");
  141. lt1.addActionListener(new java.awt.event.ActionListener() {
  142. public void actionPerformed(java.awt.event.ActionEvent evt) {
  143. lt1ActionPerformed(evt);
  144. }
  145. });
  146.  
  147. lgroup.add(lt2);
  148. lt2.setText("RED GAMING");
  149. lt2.addActionListener(new java.awt.event.ActionListener() {
  150. public void actionPerformed(java.awt.event.ActionEvent evt) {
  151. lt2ActionPerformed(evt);
  152. }
  153. });
  154.  
  155. lgroup.add(lt3);
  156. lt3.setText("FLOW");
  157. lt3.addActionListener(new java.awt.event.ActionListener() {
  158. public void actionPerformed(java.awt.event.ActionEvent evt) {
  159. lt3ActionPerformed(evt);
  160. }
  161. });
  162.  
  163. lgroup.add(lt4);
  164. lt4.setText("lt4");
  165. lt4.addActionListener(new java.awt.event.ActionListener() {
  166. public void actionPerformed(java.awt.event.ActionEvent evt) {
  167. lt4ActionPerformed(evt);
  168. }
  169. });
  170.  
  171. rgroup.add(rt1);
  172. rt1.setText("DEFAULT");
  173. rt1.addActionListener(new java.awt.event.ActionListener() {
  174. public void actionPerformed(java.awt.event.ActionEvent evt) {
  175. rt1ActionPerformed(evt);
  176. }
  177. });
  178.  
  179. rgroup.add(rt2);
  180. rt2.setText("RED GAMING");
  181. rt2.addActionListener(new java.awt.event.ActionListener() {
  182. public void actionPerformed(java.awt.event.ActionEvent evt) {
  183. rt2ActionPerformed(evt);
  184. }
  185. });
  186.  
  187. rgroup.add(rt3);
  188. rt3.setText("FLOW");
  189. rt3.addActionListener(new java.awt.event.ActionListener() {
  190. public void actionPerformed(java.awt.event.ActionEvent evt) {
  191. rt3ActionPerformed(evt);
  192. }
  193. });
  194.  
  195. rgroup.add(rt4);
  196. rt4.setText("rt4");
  197.  
  198. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  199. jPanel1.setLayout(jPanel1Layout);
  200. jPanel1Layout.setHorizontalGroup(
  201. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  202. .addGroup(jPanel1Layout.createSequentialGroup()
  203. .addGap(25, 25, 25)
  204. .addComponent(jLabel1)
  205. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  206. .addComponent(jLabel2)
  207. .addGap(29, 29, 29))
  208. .addGroup(jPanel1Layout.createSequentialGroup()
  209. .addGap(50, 50, 50)
  210. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  211. .addGroup(jPanel1Layout.createSequentialGroup()
  212. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  213. .addComponent(lr)
  214. .addComponent(jRadioButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  215. .addGap(34, 34, 34)
  216. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  217. .addComponent(jRadioButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  218. .addComponent(lg))
  219. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  220. .addGroup(jPanel1Layout.createSequentialGroup()
  221. .addGap(33, 33, 33)
  222. .addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
  223. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  224. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  225. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1053, Short.MAX_VALUE)
  226. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  227. .addGroup(jPanel1Layout.createSequentialGroup()
  228. .addComponent(jRadioButton3)
  229. .addGap(31, 31, 31)
  230. .addComponent(jRadioButton4))
  231. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  232. .addComponent(rt1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  233. .addComponent(rt4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  234. .addComponent(rt3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  235. .addComponent(rt2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  236. .addGap(93, 93, 93))))
  237. .addGroup(jPanel1Layout.createSequentialGroup()
  238. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  239. .addComponent(lt3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  240. .addComponent(lt2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  241. .addComponent(lt4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  242. .addComponent(lt1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  243. .addGap(0, 0, Short.MAX_VALUE))))
  244. );
  245. jPanel1Layout.setVerticalGroup(
  246. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  247. .addGroup(jPanel1Layout.createSequentialGroup()
  248. .addGap(20, 20, 20)
  249. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  250. .addComponent(jLabel1)
  251. .addComponent(jLabel2))
  252. .addGap(18, 18, 18)
  253. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  254. .addComponent(jRadioButton1)
  255. .addComponent(jRadioButton2)
  256. .addComponent(jRadioButton3)
  257. .addComponent(jRadioButton4))
  258. .addGap(39, 39, 39)
  259. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  260. .addComponent(lt1)
  261. .addComponent(rt1))
  262. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  263. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  264. .addComponent(lt2)
  265. .addComponent(rt2))
  266. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  267. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  268. .addComponent(lt3)
  269. .addComponent(rt3))
  270. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  271. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  272. .addComponent(lt4)
  273. .addComponent(rt4))
  274. .addGap(131, 131, 131)
  275. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  276. .addComponent(lr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  277. .addComponent(lg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  278. .addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  279. .addContainerGap(409, Short.MAX_VALUE))
  280. );
  281.  
  282. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  283. getContentPane().setLayout(layout);
  284. layout.setHorizontalGroup(
  285. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  286. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  287. );
  288. layout.setVerticalGroup(
  289. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  290. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  291. );
  292.  
  293. pack();
  294. }// </editor-fold>
  295.  
  296.  
  297. private void lampOn() {
  298. try {
  299. lampa = true;
  300. dv1.setPower(true);
  301. dv2.setPower(true);
  302. dv3.setPower(true);
  303. lampBright();
  304. } catch(Exception e) { e.printStackTrace(); }
  305. }
  306. private void lampOff() {
  307. try {
  308. lampa = false;
  309. dv1.setPower(false);
  310. dv2.setPower(false);
  311. dv3.setPower(false);
  312. lgroup.clearSelection();
  313. } catch(Exception e) { e.printStackTrace(); }
  314. }
  315. private void lampColor(String r, String g, String b) {
  316. try {
  317. if (!r.matches("[0-9]+")) {
  318. r = "0";
  319. lr.setText("0");
  320. }
  321. if (!g.matches("[0-9]+")) {
  322. g = "0";
  323. lg.setText("0");
  324. }
  325. if (!b.matches("[0-9]+")) {
  326. b = "0";
  327. lb.setText("0");
  328. }
  329. dv1.setRGB(Integer.parseInt(r),Integer.parseInt(g),Integer.parseInt(b));
  330. dv2.setRGB(Integer.parseInt(r),Integer.parseInt(g),Integer.parseInt(b));
  331. dv3.setRGB(Integer.parseInt(r),Integer.parseInt(g),Integer.parseInt(b));
  332. } catch(Exception e) { e.printStackTrace(); }
  333. }
  334.  
  335. private void lampTemp(int temp) {
  336. try {
  337. dv1.setColorTemperature(temp);
  338. dv2.setColorTemperature(temp);
  339. dv3.setColorTemperature(temp);
  340. } catch(Exception e) { e.printStackTrace(); }
  341. }
  342.  
  343. private void lampBright() {
  344. for(int i=0 ; i<=1 ; i++) {
  345. if(bright>=100) {
  346. bright = 100;
  347. break;
  348. }
  349. if(bright<=0) {
  350. bright = 0;
  351. break;
  352. }
  353. System.out.println("Bright = " + bright);
  354. try {
  355. dv1.setBrightness(bright);
  356. dv2.setBrightness(bright);
  357. dv3.setBrightness(bright);
  358. } catch(Exception e) { e.printStackTrace(); }
  359. }
  360. }
  361.  
  362. private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  363. // LAMPA ON
  364. jRadioButton1.setSelected(true);
  365. jRadioButton2.setSelected(false);
  366. lampOn();
  367. }
  368.  
  369. private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  370. // LAMPA OFF
  371. jRadioButton1.setSelected(false);
  372. jRadioButton2.setSelected(true);
  373. lampOff();
  374. }
  375.  
  376. private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  377. // PC ON
  378. jRadioButton3.setSelected(true);
  379. jRadioButton4.setSelected(false);
  380. rt1.setSelected(true);
  381. try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --static=White --brightness 100"); } catch(Exception e){e.printStackTrace();}
  382. }
  383.  
  384. private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
  385. // PC OFF
  386. jRadioButton3.setSelected(false);
  387. jRadioButton4.setSelected(true);
  388. lgroup.clearSelection();
  389. try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --static=Red --brightness 0"); } catch(Exception e){e.printStackTrace();}
  390. }
  391.  
  392. private void lrActionPerformed(java.awt.event.ActionEvent evt) {
  393. lampColor(lr.getText(), lg.getText(), lb.getText());
  394. lgroup.clearSelection();
  395. }
  396.  
  397. private void lgActionPerformed(java.awt.event.ActionEvent evt) {
  398. lampColor(lr.getText(), lg.getText(), lb.getText());
  399. lgroup.clearSelection();
  400. }
  401.  
  402. private void lbActionPerformed(java.awt.event.ActionEvent evt) {
  403. lampColor(lr.getText(), lg.getText(), lb.getText());
  404. lgroup.clearSelection();
  405. }
  406.  
  407. private void lt1ActionPerformed(java.awt.event.ActionEvent evt) {
  408. // default
  409. jRadioButton1.doClick();
  410. lampTemp(4200);
  411. }
  412.  
  413. private void lt2ActionPerformed(java.awt.event.ActionEvent evt) {
  414. // red gaming
  415. jRadioButton1.doClick();
  416. lampColor("255", "30", "0");
  417. }
  418.  
  419. private void lt3ActionPerformed(java.awt.event.ActionEvent evt) {
  420. // flow
  421. try {
  422. YeelightFlow flow;
  423. YeelightFlowAction action = null;
  424.  
  425. flow = new YeelightFlow(100, action);
  426. } catch(Exception e) { }
  427. }
  428.  
  429. private void lt4ActionPerformed(java.awt.event.ActionEvent evt) {
  430. // TODO add your handling code here:
  431. }
  432.  
  433. private void rt1ActionPerformed(java.awt.event.ActionEvent evt) {
  434. // DEFAULT
  435. jRadioButton3.doClick();
  436. }
  437.  
  438. private void rt2ActionPerformed(java.awt.event.ActionEvent evt) {
  439. // RED GAMING
  440. jRadioButton3.setSelected(true);
  441. try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --zone=1 --static=ff0600 --brightness=90 " + "--zone=2 --static=ff0600 --brightness=0 " + "--zone=3 --static=ff0600 --brightness=0 " + "--zone=4 --static=ff0600 --brightness=90 "); } catch(Exception e){e.printStackTrace();}
  442. }
  443.  
  444. private void rt3ActionPerformed(java.awt.event.ActionEvent evt) {
  445. jRadioButton3.setSelected(true);
  446. try { Runtime.getRuntime().exec("fusion/RGBFusionTool.exe --colorcycle=16"); } catch(Exception e){e.printStackTrace();}
  447. }
  448.  
  449. public void nativeKeyPressed(NativeKeyEvent e) {
  450. //isAltPressed = (e.getModifiers() & NativeKeyEvent.ALT_MASK) != 0;
  451. }
  452.  
  453. public void nativeKeyReleased(NativeKeyEvent e) {
  454. //System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
  455. isAltPressed = (e.getModifiers() & NativeKeyEvent.ALT_MASK) != 0;
  456. if(e.getKeyCode() == NativeKeyEvent.VC_8 & isAltPressed) {
  457. if(lampa) {
  458. jRadioButton2.doClick();
  459. } else {
  460. jRadioButton1.doClick();
  461. }
  462. }
  463. }
  464.  
  465. public void nativeKeyTyped(NativeKeyEvent e) {
  466. }
  467.  
  468. public void nativeMouseWheelMoved(NativeMouseWheelEvent e) {
  469. //System.out.println("Mosue Wheel Moved: " + e.getWheelRotation());
  470. isAltPressed = (e.getModifiers() & NativeKeyEvent.ALT_MASK) != 0;
  471. if(e.getWheelRotation()==1 & isAltPressed) { // w tyl
  472. bright = bright-10;
  473. lampBright();
  474. } else if (e.getWheelRotation()!=1 & isAltPressed) { // w przod
  475. bright = bright+10;
  476. lampBright();
  477. }
  478. }
  479.  
  480. /**
  481. * @param args the command line arguments
  482. */
  483. public static void main(String args[]) {
  484. /* Set the Nimbus look and feel */
  485. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  486. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  487. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  488. */
  489. try {
  490. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  491. if ("Nimbus".equals(info.getName())) {
  492. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  493. break;
  494. }
  495. }
  496. } catch (ClassNotFoundException ex) {
  497. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  498. } catch (InstantiationException ex) {
  499. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  500. } catch (IllegalAccessException ex) {
  501. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  502. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  503. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  504. }
  505. //</editor-fold>
  506.  
  507. /* Create and display the form */
  508. java.awt.EventQueue.invokeLater(new Runnable() {
  509. public void run() {
  510. new Main().setVisible(true);
  511. }
  512. });
  513. try {
  514. Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
  515. logger.setLevel(Level.WARNING);
  516. logger.setUseParentHandlers(false);
  517. GlobalScreen.registerNativeHook();
  518. }
  519. catch (NativeHookException ex) {
  520. System.err.println("There was a problem registering the native hook.");
  521. System.err.println(ex.getMessage());
  522.  
  523. System.exit(1);
  524. }
  525. GlobalScreen.addNativeKeyListener(new Main());
  526. GlobalScreen.addNativeMouseWheelListener(new Main());
  527. }
  528.  
  529. // Variables declaration - do not modify
  530. private javax.swing.JLabel jLabel1;
  531. private javax.swing.JLabel jLabel2;
  532. private javax.swing.JPanel jPanel1;
  533. private javax.swing.JRadioButton jRadioButton1;
  534. private javax.swing.JRadioButton jRadioButton2;
  535. private javax.swing.JRadioButton jRadioButton3;
  536. private javax.swing.JRadioButton jRadioButton4;
  537. private javax.swing.JTextField lb;
  538. private javax.swing.JTextField lg;
  539. private javax.swing.ButtonGroup lgroup;
  540. private javax.swing.JTextField lr;
  541. private javax.swing.JRadioButton lt1;
  542. private javax.swing.JRadioButton lt2;
  543. private javax.swing.JRadioButton lt3;
  544. private javax.swing.JRadioButton lt4;
  545. private javax.swing.ButtonGroup rgroup;
  546. private javax.swing.JRadioButton rt1;
  547. private javax.swing.JRadioButton rt2;
  548. private javax.swing.JRadioButton rt3;
  549. private javax.swing.JRadioButton rt4;
  550. // End of variables declaration
  551.  
  552. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement