Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package lab7;
- import java.util.Locale;
- import java.util.ResourceBundle;
- import java.lang.management.ManagementFactory;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.management.ObjectName;
- import javax.management.JMException;
- import javax.management.Notification;
- import javax.management.NotificationListener;
- import lab7.ApplicationMBeanImpl;
- /**
- *
- * @author buharin
- */
- public class JGui extends javax.swing.JFrame implements NotificationListener{
- private Locale locale = Locale.getDefault();
- private ResourceBundle rb;
- private ApplicationMBeanImpl mbean;
- /**
- * Creates new form JGui
- */
- public JGui() {
- initComponents();
- internacjonalizacjaInterfejsu(locale);
- try {
- initManagement();
- } catch (Exception ex) {
- System.out.println("Źle się załadowało.");
- }
- initMBeanValues();
- }
- private void internacjonalizacjaInterfejsu(Locale locale)
- {
- rb = ResourceBundle.getBundle("resources.Tlumaczenia", locale);
- name.setText(rb.getString("name"));
- sex.setText(rb.getString("sex"));
- jRadioButtonKobieta.setText(rb.getString("kobieta"));
- if(!jTextField1.getText().isEmpty()) {
- String str = "";
- if(jRadioButtonKobieta.isSelected())
- str = rb.getString("miss");
- if(jRadioButtonMale.isSelected())
- str = rb.getString("mister");
- jHello.setText(rb.getString("hello")+" "+str+" "+jTextField1.getText());
- jMessage.setText(rb.getString("greeting"));
- }
- }
- /**
- * 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">
- private void initComponents() {
- buttonGroup2 = new javax.swing.ButtonGroup();
- jComboBox1 = new javax.swing.JComboBox();
- name = new javax.swing.JLabel();
- sex = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jRadioButtonKobieta = new javax.swing.JRadioButton();
- jRadioButtonMale = new javax.swing.JRadioButton();
- jHello = new javax.swing.JLabel();
- jMessage = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Lab7");
- jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "PL", "EN" }));
- jComboBox1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jComboBox1ActionPerformed(evt);
- }
- });
- name.setText("jLabel1");
- sex.setText("jLabel1");
- buttonGroup2.add(jRadioButtonKobieta);
- jRadioButtonKobieta.setText("K");
- jRadioButtonKobieta.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButtonKobietaActionPerformed(evt);
- }
- });
- buttonGroup2.add(jRadioButtonMale);
- jRadioButtonMale.setText("M");
- jRadioButtonMale.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButtonMaleActionPerformed(evt);
- }
- });
- jHello.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- jMessage.setFont(new java.awt.Font("Cantarell", 1, 15)); // NOI18N
- 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()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jHello, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(name)
- .addComponent(sex))
- .addGap(44, 44, 44)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jRadioButtonKobieta)
- .addGap(18, 18, 18)
- .addComponent(jRadioButtonMale)))
- .addGap(0, 73, Short.MAX_VALUE))
- .addComponent(jMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jComboBox1, 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.BASELINE)
- .addComponent(name)
- .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(sex)
- .addComponent(jRadioButtonKobieta)
- .addComponent(jRadioButtonMale))
- .addGap(56, 56, 56)
- .addComponent(jHello, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(26, 26, 26)
- .addComponent(jMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(27, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
- if((jComboBox1.getSelectedItem()).toString().equalsIgnoreCase("EN"))
- {
- locale = new Locale("en", "EN");
- internacjonalizacjaInterfejsu(locale);
- } else {
- locale = new Locale("pl", "PL");
- internacjonalizacjaInterfejsu(locale);
- }
- }
- private void jRadioButtonKobietaActionPerformed(java.awt.event.ActionEvent evt) {
- if(jRadioButtonKobieta.isSelected()) {
- internacjonalizacjaInterfejsu(locale);
- }
- }
- private void jRadioButtonMaleActionPerformed(java.awt.event.ActionEvent evt) {
- if(jRadioButtonMale.isSelected()) {
- internacjonalizacjaInterfejsu(locale);
- }
- }
- private void initManagement() throws Exception {
- try { // Register MBean in Platform MBeanServer
- mbean = new ApplicationMBeanImpl();
- ManagementFactory.getPlatformMBeanServer().
- registerMBean(mbean,
- new ObjectName("lab7:type=ApplicationMBeanImpl"));
- } catch (JMException ex) {
- ex.printStackTrace();
- }
- }
- private void initMBeanValues() {
- jTextField1.setText(mbean.getName());
- if(mbean.getKraj().equalsIgnoreCase("pl") || mbean.getKraj().equalsIgnoreCase("en")){
- locale = new Locale(mbean.getKraj().toLowerCase());
- internacjonalizacjaInterfejsu(locale);
- }
- if(mbean.getSex().equalsIgnoreCase("m"))
- jRadioButtonMale.setSelected(true);
- if(mbean.getSex().equalsIgnoreCase("k"))
- jRadioButtonKobieta.setSelected(true);
- }
- /**
- * @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(JGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(JGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(JGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(JGui.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 JGui().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.ButtonGroup buttonGroup2;
- private javax.swing.JComboBox jComboBox1;
- private javax.swing.JLabel jHello;
- private javax.swing.JLabel jMessage;
- private javax.swing.JRadioButton jRadioButtonKobieta;
- private javax.swing.JRadioButton jRadioButtonMale;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JLabel name;
- private javax.swing.JLabel sex;
- // End of variables declaration
- @Override
- public void handleNotification(Notification ntfctn, Object o) {
- System.out.println(ntfctn.toString());
- System.out.println(o.getClass().toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement