Daryan997

Untitled

Apr 25th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.94 KB | None | 0 0
  1.  
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import javax.swing.ImageIcon;
  5.  
  6. /*
  7. * To change this license header, choose License Headers in Project Properties.
  8. * To change this template file, choose Tools | Templates
  9. * and open the template in the editor.
  10. */
  11.  
  12. /**
  13. *
  14. * @author darya
  15. */
  16. public class NewJFrame extends javax.swing.JFrame {
  17.  
  18. /**
  19. * Creates new form NewJFrame
  20. */
  21. public NewJFrame() {
  22. initComponents();
  23. buttonGroup1.add(jRadioButton1);
  24. buttonGroup1.add(jRadioButton2);
  25. buttonGroup1.add(jRadioButton3);
  26. }
  27.  
  28. /**
  29. * This method is called from within the constructor to initialize the form.
  30. * WARNING: Do NOT modify this code. The content of this method is always
  31. * regenerated by the Form Editor.
  32. */
  33. @SuppressWarnings("unchecked")
  34. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  35. private void initComponents() {
  36.  
  37. buttonGroup1 = new javax.swing.ButtonGroup();
  38. jPanel2 = new javax.swing.JPanel();
  39. jLabel1 = new javax.swing.JLabel();
  40. jLabel2 = new javax.swing.JLabel();
  41. jLabel3 = new javax.swing.JLabel();
  42. jToggleButton1 = new javax.swing.JToggleButton();
  43. jPanel1 = new javax.swing.JPanel();
  44. jLabel4 = new javax.swing.JLabel();
  45. jComboBox1 = new javax.swing.JComboBox<>();
  46. jTextField1 = new javax.swing.JTextField();
  47. jLabel5 = new javax.swing.JLabel();
  48. jCheckBox1 = new javax.swing.JCheckBox();
  49. jRadioButton1 = new javax.swing.JRadioButton();
  50. jRadioButton2 = new javax.swing.JRadioButton();
  51. jRadioButton3 = new javax.swing.JRadioButton();
  52. jButton1 = new javax.swing.JButton();
  53. jButton2 = new javax.swing.JButton();
  54.  
  55. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  56. getContentPane().setLayout(new java.awt.GridLayout(1, 2));
  57.  
  58. jPanel2.setBackground(new java.awt.Color(204, 204, 204));
  59.  
  60. jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
  61. jLabel1.setText("homework 1");
  62.  
  63. jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/content-icon.png"))); // NOI18N
  64.  
  65. jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
  66. jLabel3.setText("screen mode");
  67.  
  68. jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/off.png"))); // NOI18N
  69. jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
  70. public void actionPerformed(java.awt.event.ActionEvent evt) {
  71. jToggleButton1ActionPerformed(evt);
  72. }
  73. });
  74.  
  75. javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  76. jPanel2.setLayout(jPanel2Layout);
  77. jPanel2Layout.setHorizontalGroup(
  78. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  79. .addGroup(jPanel2Layout.createSequentialGroup()
  80. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  81. .addGroup(jPanel2Layout.createSequentialGroup()
  82. .addGap(66, 66, 66)
  83. .addComponent(jLabel2))
  84. .addGroup(jPanel2Layout.createSequentialGroup()
  85. .addGap(124, 124, 124)
  86. .addComponent(jLabel1))
  87. .addGroup(jPanel2Layout.createSequentialGroup()
  88. .addGap(56, 56, 56)
  89. .addComponent(jToggleButton1)
  90. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  91. .addComponent(jLabel3)))
  92. .addContainerGap(116, Short.MAX_VALUE))
  93. );
  94. jPanel2Layout.setVerticalGroup(
  95. jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  96. .addGroup(jPanel2Layout.createSequentialGroup()
  97. .addGap(60, 60, 60)
  98. .addComponent(jLabel1)
  99. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  100. .addComponent(jLabel2)
  101. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
  102. .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103. .addComponent(jToggleButton1, javax.swing.GroupLayout.Alignment.TRAILING)
  104. .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
  105. .addGap(36, 36, 36))
  106. );
  107.  
  108. getContentPane().add(jPanel2);
  109.  
  110. jPanel1.setBackground(java.awt.Color.white);
  111.  
  112. jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  113. jLabel4.setText("enter a sentence");
  114.  
  115. jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "select font", "bold", "italic", "bold-italic", "plain" }));
  116. jComboBox1.addActionListener(new java.awt.event.ActionListener() {
  117. public void actionPerformed(java.awt.event.ActionEvent evt) {
  118. jComboBox1ActionPerformed(evt);
  119. }
  120. });
  121.  
  122. jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  123. jLabel5.setText("select your subject");
  124.  
  125. jCheckBox1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  126. jCheckBox1.setText("agree to conditions and terms");
  127. jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
  128. public void actionPerformed(java.awt.event.ActionEvent evt) {
  129. jCheckBox1ActionPerformed(evt);
  130. }
  131. });
  132.  
  133. jRadioButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  134. jRadioButton1.setText("programming");
  135. jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
  136. public void actionPerformed(java.awt.event.ActionEvent evt) {
  137. jRadioButton1ActionPerformed(evt);
  138. }
  139. });
  140.  
  141. jRadioButton2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  142. jRadioButton2.setText("database");
  143. jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
  144. public void actionPerformed(java.awt.event.ActionEvent evt) {
  145. jRadioButton2ActionPerformed(evt);
  146. }
  147. });
  148.  
  149. jRadioButton3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  150. jRadioButton3.setText("network");
  151. jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
  152. public void actionPerformed(java.awt.event.ActionEvent evt) {
  153. jRadioButton3ActionPerformed(evt);
  154. }
  155. });
  156.  
  157. jButton1.setText("finish");
  158. jButton1.setEnabled(false);
  159.  
  160. jButton2.setText("reset");
  161. jButton2.addActionListener(new java.awt.event.ActionListener() {
  162. public void actionPerformed(java.awt.event.ActionEvent evt) {
  163. jButton2ActionPerformed(evt);
  164. }
  165. });
  166.  
  167. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  168. jPanel1.setLayout(jPanel1Layout);
  169. jPanel1Layout.setHorizontalGroup(
  170. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  171. .addGroup(jPanel1Layout.createSequentialGroup()
  172. .addGap(59, 59, 59)
  173. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  174. .addGroup(jPanel1Layout.createSequentialGroup()
  175. .addComponent(jTextField1)
  176. .addGap(18, 18, 18)
  177. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
  178. .addGap(42, 42, 42))
  179. .addGroup(jPanel1Layout.createSequentialGroup()
  180. .addComponent(jLabel4)
  181. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  182. .addGroup(jPanel1Layout.createSequentialGroup()
  183. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  184. .addGroup(jPanel1Layout.createSequentialGroup()
  185. .addComponent(jButton2)
  186. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  187. .addComponent(jButton1))
  188. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  189. .addGroup(jPanel1Layout.createSequentialGroup()
  190. .addComponent(jRadioButton1)
  191. .addGap(18, 18, 18)
  192. .addComponent(jRadioButton2)
  193. .addGap(18, 18, 18)
  194. .addComponent(jRadioButton3))
  195. .addComponent(jCheckBox1)
  196. .addComponent(jLabel5)))
  197. .addGap(0, 42, Short.MAX_VALUE))))
  198. );
  199. jPanel1Layout.setVerticalGroup(
  200. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  201. .addGroup(jPanel1Layout.createSequentialGroup()
  202. .addGap(49, 49, 49)
  203. .addComponent(jLabel4)
  204. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  205. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  206. .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  207. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  208. .addGap(68, 68, 68)
  209. .addComponent(jLabel5)
  210. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  211. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  212. .addComponent(jRadioButton1)
  213. .addComponent(jRadioButton2)
  214. .addComponent(jRadioButton3))
  215. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 126, Short.MAX_VALUE)
  216. .addComponent(jCheckBox1)
  217. .addGap(83, 83, 83)
  218. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  219. .addComponent(jButton1)
  220. .addComponent(jButton2))
  221. .addContainerGap())
  222. );
  223.  
  224. getContentPane().add(jPanel1);
  225.  
  226. pack();
  227. }// </editor-fold>
  228.  
  229. private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
  230. if (jCheckBox1.isSelected()) {
  231. jButton1.setEnabled(true);
  232. } else {
  233. jButton1.setEnabled(false);
  234. }
  235. }
  236.  
  237. private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  238. if (jToggleButton1.isSelected()) {
  239. ImageIcon ic = new ImageIcon("src\\on.png");
  240. jToggleButton1.setIcon(ic);
  241.  
  242. jPanel1.setBackground(Color.black);
  243.  
  244. jPanel2.setBackground(Color.white);
  245. jLabel4.setForeground(Color.white);
  246. jLabel5.setForeground(Color.white);
  247. jRadioButton1.setForeground(Color.white);
  248. jRadioButton2.setForeground(Color.white);
  249. jRadioButton3.setForeground(Color.white);
  250. jCheckBox1.setForeground(Color.white);
  251. } else {
  252. ImageIcon ic = new ImageIcon("src\\off.png");
  253. jToggleButton1.setIcon(ic);
  254. jPanel1.setBackground(Color.white);
  255. jPanel2.setBackground(Color.lightGray);
  256. jLabel4.setForeground(Color.black);
  257. jLabel5.setForeground(Color.black);
  258. jRadioButton1.setForeground(Color.black);
  259. jRadioButton2.setForeground(Color.black);
  260. jRadioButton3.setForeground(Color.black);
  261. jCheckBox1.setForeground(Color.black);
  262. }
  263. }
  264.  
  265. private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  266. if (jRadioButton1.isSelected()) {
  267. jRadioButton1.setForeground(Color.pink);
  268. if (jToggleButton1.isSelected()) {
  269. jRadioButton2.setForeground(Color.white);
  270. jRadioButton2.setForeground(Color.white);
  271. } else {
  272. jRadioButton2.setForeground(Color.black);
  273. jRadioButton3.setForeground(Color.black);
  274. }
  275. } else if (jRadioButton2.isSelected()) {
  276. jRadioButton2.setForeground(Color.pink);
  277. if (jToggleButton1.isSelected()) {
  278. jRadioButton1.setForeground(Color.white);
  279. jRadioButton3.setForeground(Color.white);
  280. } else {
  281. jRadioButton1.setForeground(Color.black);
  282. jRadioButton3.setForeground(Color.black);
  283. }
  284. } else if (jRadioButton3.isSelected()) {
  285. jRadioButton3.setForeground(Color.pink);
  286. if (jToggleButton1.isSelected()) {
  287. jRadioButton1.setForeground(Color.white);
  288. jRadioButton2.setForeground(Color.white);
  289. } else {
  290. jRadioButton1.setForeground(Color.black);
  291. jRadioButton2.setForeground(Color.black);
  292. }
  293. }
  294. }
  295.  
  296. private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  297. if (jRadioButton1.isSelected()) {
  298. jRadioButton1.setForeground(Color.pink);
  299. if (jToggleButton1.isSelected()) {
  300. jRadioButton2.setForeground(Color.white);
  301. jRadioButton2.setForeground(Color.white);
  302. } else {
  303. jRadioButton2.setForeground(Color.black);
  304. jRadioButton3.setForeground(Color.black);
  305. }
  306. } else if (jRadioButton2.isSelected()) {
  307. jRadioButton2.setForeground(Color.pink);
  308. if (jToggleButton1.isSelected()) {
  309. jRadioButton1.setForeground(Color.white);
  310. jRadioButton3.setForeground(Color.white);
  311. } else {
  312. jRadioButton1.setForeground(Color.black);
  313. jRadioButton3.setForeground(Color.black);
  314. }
  315. } else if (jRadioButton3.isSelected()) {
  316. jRadioButton3.setForeground(Color.pink);
  317. if (jToggleButton1.isSelected()) {
  318. jRadioButton1.setForeground(Color.white);
  319. jRadioButton2.setForeground(Color.white);
  320. } else {
  321. jRadioButton1.setForeground(Color.black);
  322. jRadioButton2.setForeground(Color.black);
  323. }
  324. }
  325. // TODO add your handling code here:
  326. }
  327.  
  328. private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  329. if (jRadioButton1.isSelected()) {
  330. jRadioButton1.setForeground(Color.pink);
  331. if (jToggleButton1.isSelected()) {
  332. jRadioButton2.setForeground(Color.white);
  333. jRadioButton2.setForeground(Color.white);
  334. } else {
  335. jRadioButton2.setForeground(Color.black);
  336. jRadioButton3.setForeground(Color.black);
  337. }
  338. } else if (jRadioButton2.isSelected()) {
  339. jRadioButton2.setForeground(Color.pink);
  340. if (jToggleButton1.isSelected()) {
  341. jRadioButton1.setForeground(Color.white);
  342. jRadioButton3.setForeground(Color.white);
  343. } else {
  344. jRadioButton1.setForeground(Color.black);
  345. jRadioButton3.setForeground(Color.black);
  346. }
  347. } else if (jRadioButton3.isSelected()) {
  348. jRadioButton3.setForeground(Color.pink);
  349. if (jToggleButton1.isSelected()) {
  350. jRadioButton1.setForeground(Color.white);
  351. jRadioButton2.setForeground(Color.white);
  352. } else {
  353. jRadioButton1.setForeground(Color.black);
  354. jRadioButton2.setForeground(Color.black);
  355. }
  356. }
  357. }
  358.  
  359. private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
  360. if (jComboBox1.getSelectedIndex() == 1) {
  361. Font font = new Font("Arial", Font.BOLD, 13);
  362. jTextField1.setFont(font);
  363. } else if (jComboBox1.getSelectedIndex() == 2) {
  364. Font font = new Font("Arial", Font.ITALIC, 13);
  365. jTextField1.setFont(font);
  366. } else if (jComboBox1.getSelectedIndex() == 3) {
  367. Font font = new Font("Arial", Font.BOLD + Font.ITALIC, 13);
  368. jTextField1.setFont(font);
  369. } else if (jComboBox1.getSelectedIndex() == 4) {
  370. Font font = new Font("Arial", Font.PLAIN, 13);
  371. jTextField1.setFont(font);
  372. }
  373. }
  374.  
  375. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  376. jTextField1.setText("");
  377. jComboBox1.setSelectedIndex(0);
  378. buttonGroup1.clearSelection();
  379. if (jToggleButton1.isSelected()) {
  380. jRadioButton1.setForeground(Color.white);
  381. jRadioButton2.setForeground(Color.white);
  382. jRadioButton3.setForeground(Color.white);
  383. } else {
  384. jRadioButton1.setForeground(Color.black);
  385. jRadioButton2.setForeground(Color.black);
  386. jRadioButton3.setForeground(Color.black);
  387. }
  388. jCheckBox1.setSelected(false);
  389. jButton1.setEnabled(false);
  390. }
  391.  
  392. /**
  393. * @param args the command line arguments
  394. */
  395. public static void main(String args[]) {
  396. /* Set the Nimbus look and feel */
  397. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  398. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  399. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  400. */
  401. try {
  402. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  403. if ("Nimbus".equals(info.getName())) {
  404. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  405. break;
  406. }
  407. }
  408. } catch (ClassNotFoundException ex) {
  409. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  410. } catch (InstantiationException ex) {
  411. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  412. } catch (IllegalAccessException ex) {
  413. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  414. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  415. java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  416. }
  417. //</editor-fold>
  418.  
  419. /* Create and display the form */
  420. java.awt.EventQueue.invokeLater(new Runnable() {
  421. public void run() {
  422. new NewJFrame().setVisible(true);
  423. }
  424. });
  425. }
  426.  
  427. // Variables declaration - do not modify
  428. private javax.swing.ButtonGroup buttonGroup1;
  429. private javax.swing.JButton jButton1;
  430. private javax.swing.JButton jButton2;
  431. private javax.swing.JCheckBox jCheckBox1;
  432. private javax.swing.JComboBox<String> jComboBox1;
  433. private javax.swing.JLabel jLabel1;
  434. private javax.swing.JLabel jLabel2;
  435. private javax.swing.JLabel jLabel3;
  436. private javax.swing.JLabel jLabel4;
  437. private javax.swing.JLabel jLabel5;
  438. private javax.swing.JPanel jPanel1;
  439. private javax.swing.JPanel jPanel2;
  440. private javax.swing.JRadioButton jRadioButton1;
  441. private javax.swing.JRadioButton jRadioButton2;
  442. private javax.swing.JRadioButton jRadioButton3;
  443. private javax.swing.JTextField jTextField1;
  444. private javax.swing.JToggleButton jToggleButton1;
  445. // End of variables declaration
  446. }
  447.  
Add Comment
Please, Sign In to add comment