Transistor.Transistor.java Source code

Java tutorial

Introduction

Here is the source code for Transistor.Transistor.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Transistor;

import org.jfree.chart.JFreeChart;

/**
 *
 * @author Geonmo
 */
public class Transistor extends javax.swing.JApplet {

    /**
     * Initializes the applet Transistor
     */
    TransistorInfo info = TransistorInfo.getInstacne();
    JFreeChart chart;

    @Override
    public void init() {
        /* 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(Transistor.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Transistor.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Transistor.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Transistor.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        /* Create and display the applet */
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        info.setPinchOff((int) PinchOffVoltage.getValue());
        info.setVds((int) JFET_VdsSpinner.getValue());
        info.setVgs((int) JFET_VgsSpinner.getValue());
        TestButton.setVisible(false);
    }

    /**
     * This method is called from within the init() method 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">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        TransistorSelector = new javax.swing.JTabbedPane();
        JFETPanel = new javax.swing.JPanel();
        JFETViewPanel = new JFET2DViewer();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        JFETGraphPanel = new JFETGraphViewer(chart);
        JFETControlPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        JFET_VgsSlider = new javax.swing.JSlider();
        JFET_VgsSpinner = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        PinchOffVoltage = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        JFET_VdsSpinner = new javax.swing.JSpinner();
        JFET_VdsSlider = new javax.swing.JSlider();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        TestButton = new javax.swing.JButton();
        SetupButton = new javax.swing.JButton();

        setMaximumSize(new java.awt.Dimension(800, 600));
        setMinimumSize(new java.awt.Dimension(800, 600));
        setPreferredSize(new java.awt.Dimension(800, 600));

        JFETViewPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        JFETViewPanel.setMaximumSize(new java.awt.Dimension(565, 250));
        JFETViewPanel.setMinimumSize(new java.awt.Dimension(565, 250));
        JFETViewPanel.setPreferredSize(new java.awt.Dimension(565, 250));

        jLabel7.setText("Source");

        jLabel8.setText("Drain");

        jLabel9.setText("Gate");

        jLabel10.setText("Gate");

        javax.swing.GroupLayout JFETViewPanelLayout = new javax.swing.GroupLayout(JFETViewPanel);
        JFETViewPanel.setLayout(JFETViewPanelLayout);
        JFETViewPanelLayout.setHorizontalGroup(JFETViewPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(JFETViewPanelLayout.createSequentialGroup().addGap(78, 78, 78).addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel8).addGap(102, 102, 102))
                .addGroup(JFETViewPanelLayout.createSequentialGroup().addGap(263, 263, 263)
                        .addGroup(JFETViewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel10).addComponent(jLabel9))
                        .addContainerGap(272, Short.MAX_VALUE)));
        JFETViewPanelLayout.setVerticalGroup(JFETViewPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(JFETViewPanelLayout.createSequentialGroup().addGap(59, 59, 59).addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                        .addGroup(
                                JFETViewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel7).addComponent(jLabel8))
                        .addGap(68, 68, 68).addComponent(jLabel10).addGap(60, 60, 60)));

        JFETGraphPanel
                .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        JFETGraphPanel.setMaximumSize(new java.awt.Dimension(565, 254));
        JFETGraphPanel.setMinimumSize(new java.awt.Dimension(565, 254));
        JFETGraphPanel.setPreferredSize(new java.awt.Dimension(565, 254));

        javax.swing.GroupLayout JFETGraphPanelLayout = new javax.swing.GroupLayout(JFETGraphPanel);
        JFETGraphPanel.setLayout(JFETGraphPanelLayout);
        JFETGraphPanelLayout.setHorizontalGroup(JFETGraphPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE));
        JFETGraphPanelLayout.setVerticalGroup(JFETGraphPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 250, Short.MAX_VALUE));

        JFETControlPanel
                .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel1.setText("V_GS");

        JFET_VgsSlider.setMaximum(0);
        JFET_VgsSlider.setMinimum(-50);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, JFET_VgsSpinner,
                org.jdesktop.beansbinding.ELProperty.create("${value}"), JFET_VgsSlider,
                org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        JFET_VgsSpinner.setModel(new javax.swing.SpinnerNumberModel(0, -10, 0, 1));
        JFET_VgsSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                JFET_VgsSpinnerStateChanged(evt);
            }
        });

        jLabel2.setText("Pinch-off Voltage");

        PinchOffVoltage.setModel(new javax.swing.SpinnerNumberModel(-15, -50, 0, 1));
        PinchOffVoltage.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                PinchOffVoltageStateChanged(evt);
            }
        });

        jLabel3.setText("V_DS");

        JFET_VdsSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 50, 1));
        JFET_VdsSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                JFET_VdsSpinnerStateChanged(evt);
            }
        });

        JFET_VdsSlider.setMaximum(50);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, JFET_VdsSpinner,
                org.jdesktop.beansbinding.ELProperty.create("${value}"), JFET_VdsSlider,
                org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        jLabel4.setText("V");

        jLabel5.setText("V");

        jLabel6.setText("V");

        TestButton.setText("Test");
        TestButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TestButtonActionPerformed(evt);
            }
        });

        SetupButton.setText("Setup");
        SetupButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SetupButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout JFETControlPanelLayout = new javax.swing.GroupLayout(JFETControlPanel);
        JFETControlPanel.setLayout(JFETControlPanelLayout);
        JFETControlPanelLayout.setHorizontalGroup(JFETControlPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(JFETControlPanelLayout.createSequentialGroup().addContainerGap()
                        .addGroup(JFETControlPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, JFETControlPanelLayout
                                        .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                                        .addGroup(JFETControlPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(PinchOffVoltage,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 61,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(JFET_VgsSpinner,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 61,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(JFETControlPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel4).addComponent(jLabel5)))
                                .addGroup(JFETControlPanelLayout.createSequentialGroup()
                                        .addGroup(JFETControlPanelLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel1)
                                                .addComponent(JFET_VgsSlider,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 189,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel3)
                                                .addComponent(JFET_VdsSlider,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 189,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 108,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGroup(JFETControlPanelLayout.createSequentialGroup()
                                                        .addGap(121, 121, 121)
                                                        .addComponent(JFET_VdsSpinner,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 61,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jLabel6,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 13,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGroup(JFETControlPanelLayout.createSequentialGroup()
                                                        .addGap(60, 60, 60).addComponent(TestButton)))
                                        .addGap(0, 0, Short.MAX_VALUE)))
                        .addGap(11, 11, 11))
                .addGroup(JFETControlPanelLayout.createSequentialGroup().addGap(44, 44, 44)
                        .addComponent(SetupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 129,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        JFETControlPanelLayout.setVerticalGroup(JFETControlPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(JFETControlPanelLayout.createSequentialGroup().addContainerGap().addComponent(jLabel2)
                        .addGap(1, 1, 1)
                        .addGroup(JFETControlPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(PinchOffVoltage, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel4))
                        .addGap(44, 44, 44).addComponent(jLabel1).addGap(24, 24, 24)
                        .addGroup(JFETControlPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(JFET_VgsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addComponent(JFET_VgsSlider, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28).addComponent(jLabel3).addGap(23, 23, 23)
                        .addGroup(JFETControlPanelLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(JFET_VdsSpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(JFET_VdsSlider, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28).addComponent(TestButton).addGap(29, 29, 29).addComponent(SetupButton,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(112, Short.MAX_VALUE)));

        javax.swing.GroupLayout JFETPanelLayout = new javax.swing.GroupLayout(JFETPanel);
        JFETPanel.setLayout(JFETPanelLayout);
        JFETPanelLayout
                .setHorizontalGroup(
                        JFETPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(JFETPanelLayout.createSequentialGroup().addGroup(JFETPanelLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(JFETViewPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(JFETGraphPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(JFETControlPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addContainerGap()));
        JFETPanelLayout.setVerticalGroup(JFETPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(JFETPanelLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(JFETPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(JFETPanelLayout.createSequentialGroup()
                                        .addComponent(JFETViewPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 293,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(JFETGraphPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(JFETControlPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, 0)));

        JFETControlPanel.getAccessibleContext().setAccessibleName("JFETConPanel");

        TransistorSelector.addTab("JFET", JFETPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(TransistorSelector));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(TransistorSelector));

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    public void repaintPanels() {
        ((JFET2DViewer) JFETViewPanel).repaint();
        ((JFETGraphViewer) JFETGraphPanel).repaint();
    }

    private void TestButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TestButtonActionPerformed
        // TODO add your handling code here:        
        System.out.println(info.getVds());
        ((JFET2DViewer) JFETViewPanel).printInformation();

    }//GEN-LAST:event_TestButtonActionPerformed

    private void JFET_VdsSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_JFET_VdsSpinnerStateChanged
        // TODO add your handling code here:
        info.setVds((int) JFET_VdsSpinner.getValue());
        this.repaintPanels();

    }//GEN-LAST:event_JFET_VdsSpinnerStateChanged

    private void JFET_VgsSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_JFET_VgsSpinnerStateChanged
        // TODO add your handling code here:
        info.setVgs((int) JFET_VgsSpinner.getValue());
        this.repaintPanels();

    }//GEN-LAST:event_JFET_VgsSpinnerStateChanged

    private void PinchOffVoltageStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_PinchOffVoltageStateChanged
        // TODO add your handling code here:
        info.setPinchOff((int) PinchOffVoltage.getValue());
        this.repaintPanels();

    }//GEN-LAST:event_PinchOffVoltageStateChanged

    private void SetupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SetupButtonActionPerformed
        // TODO add your handling code here:
        this.repaintPanels();
    }//GEN-LAST:event_SetupButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel JFETControlPanel;
    private javax.swing.JPanel JFETGraphPanel;
    private javax.swing.JPanel JFETPanel;
    private javax.swing.JPanel JFETViewPanel;
    private javax.swing.JSlider JFET_VdsSlider;
    private javax.swing.JSpinner JFET_VdsSpinner;
    private javax.swing.JSlider JFET_VgsSlider;
    private javax.swing.JSpinner JFET_VgsSpinner;
    private javax.swing.JSpinner PinchOffVoltage;
    private javax.swing.JButton SetupButton;
    private javax.swing.JButton TestButton;
    private javax.swing.JTabbedPane TransistorSelector;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}