Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GUIFrame extends javax.swing.JFrame {
- public GUIFrame() {
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- Label = new javax.swing.JLabel();
- TextField = new javax.swing.JTextField();
- ComboBox = new javax.swing.JComboBox<>();
- Button = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- Label.setText("Label");
- ComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4" }));
- ComboBox.addItemListener(new java.awt.event.ItemListener() {
- public void itemStateChanged(java.awt.event.ItemEvent evt) {
- ComboBoxItemStateChanged(evt);
- }
- });
- Button.setText("OK");
- Button.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- ButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(ComboBox, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(TextField, javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(Label, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addGap(163, 163, 163)
- .addComponent(Button)
- .addContainerGap(165, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(Label)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(ComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 193, Short.MAX_VALUE)
- .addComponent(Button)
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void ComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {
- // TODO add your handling code here:
- String selectedValue = ComboBox.getSelectedItem().toString();
- // Установка текста для Label в зависимости от выбранной цифры
- switch (selectedValue) {
- case "1":
- Label.setText("Текст для цифры 1");
- break;
- case "2":
- Label.setText("Текст для цифры 2");
- break;
- case "3":
- Label.setText("Текст для цифры 3");
- break;
- case "4":
- Label.setText("Текст для цифры 4");
- break;
- default:
- Label.setText("Другой текст");
- break;
- }
- }
- private void ButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String title = TextField.getText();
- setTitle(title);
- }
- /**
- * @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(GUIFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(GUIFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(GUIFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(GUIFrame.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 GUIFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton Button;
- private javax.swing.JComboBox<String> ComboBox;
- private javax.swing.JLabel Label;
- private javax.swing.JTextField TextField;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement