I am trying to add functionality for autocalculate button. I am getting null pointer exception. Can you please help in resolving this
Result
listener==javaapplication2.Clockcycle[frame0,0,0,1000x788,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=EXIT_ON_CLOSE,rootPane=javax.swing.JRootPane[,8,31,984x749,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.synth.SynthBorder@5b4b77d,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
initialTargetFrequency1==50000000
initialTargetFrequency2==160000000
inputFrequency==40000000
initialTargetFrequency150000000
initialTargetFrequency2160000000
at javaapplication2.EWPLL_AutoCalculateDialog.<init>(EWPLL_AutoCalculateDialog.java:72)
at javaapplication2.EWPLL_AutoCalculateDialog$8.run(EWPLL_AutoCalculateDialog.java:434)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 8 seconds)
Below is my code
package javaapplication2;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.text.DecimalFormat;
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.text.DecimalFormat;
import javax.swing.JComboBox;
import javax.swing.JSpinner;
public class Clockcycle extends javax.swing.JFrame implements EWPApplyChangeListener{
private boolean _eventsEnabled = true;
private boolean _canRebuild = true;
private boolean _refreshGUI = true;
private boolean _refocusRefresh = true;
public Clockcycle() {
initComponents();
}
public void paintComponent()
{
_canRebuild = true;
if (_refocusRefresh == true)
{
refreshTextLabels();
_refocusRefresh = false;
}
}
public void applyEWDividerChange(int ewpllidivVal, int ewpllfbdivVal, int ewpllodivVal1, int ewpllodivVal2 )
{
_refreshGUI = false;
long poscFreq = 40000000;
long frcFreq = 8000000;
float finFreq = 0;
if (cb_ewiclk.getSelectedItem().toString().contains("POSC"))
{
finFreq = (float)poscFreq / (float)ewpllidivVal / 1000000.f;
}
else
{
finFreq = (float)frcFreq / (float)ewpllidivVal / 1000000.f;
}
refreshTextLabels();
_refreshGUI = true;
}
public void setRefocusRefresh(boolean enable)
{
_refocusRefresh = enable;
if (enable)
{
setRefreshGUI(enable);
}
}
public void setRefreshGUI(boolean enable)
{
if (enable)
{
_canRebuild = true;
}
_refreshGUI = enable;
}
public void refreshTextLabels()
{
if(_canRebuild == false || _refreshGUI == false)
{
return;
}
_canRebuild = false;
long poscFreq = 40000000;
long frcFreq = 8000000;
long lprcFreq = 32000;
long epllFreq, wpllFreq = poscFreq;
long frcDivFreq = 0;
float finFreq = 0;
float uinFreq = 0;
float ewinFreq = 0;
float fvcoFreq = 0;
float ewvcoFreq = 0;
DecimalFormat singleDigitFormat = new DecimalFormat("#.#");
DecimalFormat threeDigitFormat = new DecimalFormat("###.#");
Font fourteenCalibriBold = new Font("Calibri", Font.BOLD, 14);
Font fourteenCalibri = new Font("Calibri", Font.PLAIN, 14);
int ewpllidivVal = Integer.parseInt(cb_refdiv.getSelectedItem().toString());
int ewpllfbdivVal = Integer.parseInt(cb_fbdiv.getSelectedItem().toString());
int ewpllodivVal1 = Integer.parseInt(cb_postdiv1.getSelectedItem().toString());
int ewpllodivVal2 = Integer.parseInt(cb_postdiv2.getSelectedItem().toString());
lbl_ewrefdiv.setText(cb_refdiv.getSelectedItem().toString());
lbl_fbdiv.setText(cb_fbdiv.getSelectedItem().toString());
lbl_ewpllpostdiv1.setText(cb_postdiv1.getSelectedItem().toString());
lbl_ewpllpostdiv2.setText(cb_postdiv2.getSelectedItem().toString());
if (cb_ewiclk.getSelectedItem().toString().contains("POSC"))
{
if(ebypass.isSelected())
epllFreq = poscFreq;
else
epllFreq = (((poscFreq / ewpllidivVal)*ewpllfbdivVal) / ewpllodivVal1);
if(wbypass.isSelected())
wpllFreq = poscFreq;
else
wpllFreq = (((poscFreq / ewpllidivVal)*ewpllfbdivVal) / ewpllodivVal2);
ewinFreq = (float)poscFreq / (float)ewpllidivVal / 1000000.f;
}
else
{
epllFreq = frcFreq;
wpllFreq = frcFreq;
}
ewvcoFreq = ewinFreq * (float)ewpllfbdivVal;
lbl_ewinMHz.setText(singleDigitFormat.format(ewinFreq));
if (ewvcoFreq < 800.0 || ewvcoFreq > 1600.0)
{
lbl_ewvcoMHz.setForeground(Color.red);
}
else
{
lbl_ewvcoMHz.setForeground(Color.black);
}
lbl_ewvcoMHz.setText(threeDigitFormat.format(ewvcoFreq));
float ew_pllFreq1 = (float)epllFreq / 1000000.f;
float ew_pllFreq2 = (float)wpllFreq / 1000000.f;
lbl_ewoutMHz1.setText(threeDigitFormat.format(ew_pllFreq1));
lbl_ewoutMHz2.setText(threeDigitFormat.format(ew_pllFreq2));
lbl_epllFreq1.setText(String.valueOf(epllFreq));
lbl_wpllFreq1.setText(String.valueOf(wpllFreq));
lbl_ewinMHz.setFont(fourteenCalibri);
lbl_ewvcoMHz.setFont(fourteenCalibri);
lbl_ewoutMHz1.setFont(fourteenCalibri);
lbl_ewoutMHz2.setFont(fourteenCalibri);
}
@SuppressWarnings("unchecked")
private void initComponents() {
cb_ewiclk = new javax.swing.JComboBox<>();
cb_refdiv = new javax.swing.JComboBox<>();
lbl_refdiv = new javax.swing.JLabel();
btn_apply = new javax.swing.JButton();
btn_auto = new javax.swing.JButton();
btn_cancel = new javax.swing.JButton();
cb_postdiv2 = new javax.swing.JComboBox<>();
cb_fbdiv = new javax.swing.JComboBox<>();
lbl_fbdiv = new javax.swing.JLabel();
cb_postdiv1 = new javax.swing.JComboBox<>();
wbypass = new javax.swing.JCheckBox();
ebypass = new javax.swing.JCheckBox();
lbl_wpllFreq1 = new javax.swing.JLabel();
lbl_epllFreq1 = new javax.swing.JLabel();
lbl_ewrefdiv = new javax.swing.JLabel();
lbl_ewpllpostdiv1 = new javax.swing.JLabel();
lbl_ewpllpostdiv2 = new javax.swing.JLabel();
lbl_fpd = new javax.swing.JLabel();
lbl_fvco = new javax.swing.JLabel();
lbl_ewinMHz = new javax.swing.JLabel();
lbl_MHz6 = new javax.swing.JLabel();
lbl_ewvcoMHz = new javax.swing.JLabel();
lbl_MHz4 = new javax.swing.JLabel();
lbl_ewoutMHz1 = new javax.swing.JLabel();
lbl_MHz7 = new javax.swing.JLabel();
lbl_ewoutMHz2 = new javax.swing.JLabel();
lbl_MHz8 = new javax.swing.JLabel();
background = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setPreferredSize(new java.awt.Dimension(1000, 1000));
getContentPane().setLayout(null);
cb_ewiclk.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "POSC", "FRC" }));
cb_ewiclk.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cb_ewiclkItemStateChanged(evt);
}
});
getContentPane().add(cb_ewiclk);
cb_ewiclk.setBounds(102, 230, 70, 20);
cb_refdiv.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63" }));
cb_refdiv.setSelectedIndex(19);
cb_refdiv.setSelectedItem(20);
cb_refdiv.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cb_refdivItemStateChanged(evt);
}
});
getContentPane().add(cb_refdiv);
cb_refdiv.setBounds(207, 210, 50, 20);
lbl_refdiv.setText("1");
getContentPane().add(lbl_refdiv);
lbl_refdiv.setBounds(130, 120, 6, 14);
btn_apply.setText("Apply");
btn_apply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_applyActionPerformed(evt);
}
});
getContentPane().add(btn_apply);
btn_apply.setBounds(239, 330, 110, 23);
btn_auto.setText("Autocalculate");
btn_auto.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_autoActionPerformed(evt);
}
});
getContentPane().add(btn_auto);
btn_auto.setBounds(357, 330, 140, 23);
btn_cancel.setText("Cancel");
btn_cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_cancelActionPerformed(evt);
}
});
getContentPane().add(btn_cancel);
btn_cancel.setBounds(530, 330, 120, 23);
cb_postdiv2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63" }));
cb_postdiv2.setSelectedIndex(9);
cb_postdiv2.setSelectedItem(10);
cb_postdiv2.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cb_postdiv2ItemStateChanged(evt);
}
});
getContentPane().add(cb_postdiv2);
cb_postdiv2.setBounds(497, 280, 50, 20);
cb_fbdiv.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252", "253", "254", "255", "256", "257", "258", "259", "260", "261", "262", "263", "264", "265", "266", "267", "268", "269", "270", "271", "272", "273", "274", "275", "276", "277", "278", "279", "280", "281", "282", "283", "284", "285", "286", "287", "288", "289", "290", "291", "292", "293", "294", "295", "296", "297", "298", "299", "300", "301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312", "313", "314", "315", "316", "317", "318", "319", "320", "321", "322", "323", "324", "325", "326", "327", "328", "329", "330", "331", "332", "333", "334", "335", "336", "337", "338", "339", "340", "341", "342", "343", "344", "345", "346", "347", "348", "349", "350", "351", "352", "353", "354", "355", "356", "357", "358", "359", "360", "361", "362", "363", "364", "365", "366", "367", "368", "369", "370", "371", "372", "373", "374", "375", "376", "377", "378", "379", "380", "381", "382", "383", "384", "385", "386", "387", "388", "389", "390", "391", "392", "393", "394", "395", "396", "397", "398", "399", "400", "401", "402", "403", "404", "405", "406", "407", "408", "409", "410", "411", "412", "413", "414", "415", "416", "417", "418", "419", "420", "421", "422", "423", "424", "425", "426", "427", "428", "429", "430", "431", "432", "433", "434", "435", "436", "437", "438", "439", "440", "441", "442", "443", "444", "445", "446", "447", "448", "449", "450", "451", "452", "453", "454", "455", "456", "457", "458", "459", "460", "461", "462", "463", "464", "465", "466", "467", "468", "469", "470", "471", "472", "473", "474", "475", "476", "477", "478", "479", "480", "481", "482", "483", "484", "485", "486", "487", "488", "489", "490", "491", "492", "493", "494", "495", "496", "497", "498", "499", "500", "501", "502", "503", "504", "505", "506", "507", "508", "509", "510", "511", "512", "513", "514", "515", "516", "517", "518", "519", "520", "521", "522", "523", "524", "525", "526", "527", "528", "529", "530", "531", "532", "533", "534", "535", "536", "537", "538", "539", "540", "541", "542", "543", "544", "545", "546", "547", "548", "549", "550", "551", "552", "553", "554", "555", "556", "557", "558", "559", "560", "561", "562", "563", "564", "565", "566", "567", "568", "569", "570", "571", "572", "573", "574", "575", "576", "577", "578", "579", "580", "581", "582", "583", "584", "585", "586", "587", "588", "589", "590", "591", "592", "593", "594", "595", "596", "597", "598", "599", "600", "601", "602", "603", "604", "605", "606", "607", "608", "609", "610", "611", "612", "613", "614", "615", "616", "617", "618", "619", "620", "621", "622", "623", "624", "625", "626", "627", "628", "629", "630", "631", "632", "633", "634", "635", "636", "637", "638", "639", "640", "641", "642", "643", "644", "645", "646", "647", "648", "649", "650", "651", "652", "653", "654", "655", "656", "657", "658", "659", "660", "661", "662", "663", "664", "665", "666", "667", "668", "669", "670", "671", "672", "673", "674", "675", "676", "677", "678", "679", "680", "681", "682", "683", "684", "685", "686", "687", "688", "689", "690", "691", "692", "693", "694", "695", "696", "697", "698", "699", "700", "701", "702", "703", "704", "705", "706", "707", "708", "709", "710", "711", "712", "713", "714", "715", "716", "717", "718", "719", "720", "721", "722", "723", "724", "725", "726", "727", "728", "729", "730", "731", "732", "733", "734", "735", "736", "737", "738", "739", "740", "741", "742", "743", "744", "745", "746", "747", "748", "749", "750", "751", "752", "753", "754", "755", "756", "757", "758", "759", "760", "761", "762", "763", "764", "765", "766", "767", "768", "769", "770", "771", "772", "773", "774", "775", "776", "777", "778", "779", "780", "781", "782", "783", "784", "785", "786", "787", "788", "789", "790", "791", "792", "793", "794", "795", "796", "797", "798", "799", "800", "801", "802", "803", "804", "805", "806", "807", "808", "809", "810", "811", "812", "813", "814", "815", "816", "817", "818", "819", "820", "821", "822", "823", "824", "825", "826", "827", "828", "829", "830", "831", "832", "833", "834", "835", "836", "837", "838", "839", "840", "841", "842", "843", "844", "845", "846", "847", "848", "849", "850", "851", "852", "853", "854", "855", "856", "857", "858", "859", "860", "861", "862", "863", "864", "865", "866", "867", "868", "869", "870", "871", "872", "873", "874", "875", "876", "877", "878", "879", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889", "890", "891", "892", "893", "894", "895", "896", "897", "898", "899", "900", "901", "902", "903", "904", "905", "906", "907", "908", "909", "910", "911", "912", "913", "914", "915", "916", "917", "918", "919", "920", "921", "922", "923", "924", "925", "926", "927", "928", "929", "930", "931", "932", "933", "934", "935", "936", "937", "938", "939", "940", "941", "942", "943", "944", "945", "946", "947", "948", "949", "950", "951", "952", "953", "954", "955", "956", "957", "958", "959", "960", "961", "962", "963", "964", "965", "966", "967", "968", "969", "970", "971", "972", "973", "974", "975", "976", "977", "978", "979", "980", "981", "982", "983", "984", "985", "986", "987", "988", "989", "990", "991", "992", "993", "994", "995", "996", "997", "998", "999", "1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009", "1010", "1011", "1012", "1013", "1014", "1015", "1016", "1017", "1018", "1019", "1020", "1021", "1022", "1023" }));
cb_fbdiv.setSelectedIndex(784);
cb_fbdiv.setSelectedItem(800);
cb_fbdiv.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cb_fbdivItemStateChanged(evt);
}
});
getContentPane().add(cb_fbdiv);
cb_fbdiv.setBounds(329, 280, 60, 20);
lbl_fbdiv.setText("800");
getContentPane().add(lbl_fbdiv);
lbl_fbdiv.setBounds(370, 220, 30, 14);
cb_postdiv1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63" }));
cb_postdiv1.setSelectedIndex(31);
cb_postdiv1.setSelectedItem(32);
cb_postdiv1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cb_postdiv1ItemStateChanged(evt);
}
});
getContentPane().add(cb_postdiv1);
cb_postdiv1.setBounds(497, 150, 50, 20);
wbypass.setText("BYPASS");
wbypass.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
wbypassItemStateChanged(evt);
}
});
getContentPane().add(wbypass);
wbypass.setBounds(660, 280, 80, 23);
ebypass.setText("BYPASS");
ebypass.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
ebypassItemStateChanged(evt);
}
});
getContentPane().add(ebypass);
ebypass.setBounds(660, 140, 80, 23);
lbl_wpllFreq1.setText("160000000");
getContentPane().add(lbl_wpllFreq1);
lbl_wpllFreq1.setBounds(720, 220, 80, 14);
lbl_epllFreq1.setText("50000000");
getContentPane().add(lbl_epllFreq1);
lbl_epllFreq1.setBounds(720, 60, 80, 14);
lbl_ewrefdiv.setText("20");
getContentPane().add(lbl_ewrefdiv);
lbl_ewrefdiv.setBounds(230, 140, 30, 14);
lbl_ewpllpostdiv1.setText("32");
getContentPane().add(lbl_ewpllpostdiv1);
lbl_ewpllpostdiv1.setBounds(530, 80, 20, 14);
lbl_ewpllpostdiv2.setText("10");
getContentPane().add(lbl_ewpllpostdiv2);
lbl_ewpllpostdiv2.setBounds(520, 220, 30, 14);
getContentPane().add(lbl_fpd);
lbl_fpd.setBounds(290, 100, 0, 0);
getContentPane().add(lbl_fvco);
lbl_fvco.setBounds(410, 110, 0, 0);
lbl_ewinMHz.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_ewinMHz.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
getContentPane().add(lbl_ewinMHz);
lbl_ewinMHz.setBounds(250, 110, 50, 20);
lbl_MHz6.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_MHz6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbl_MHz6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
getContentPane().add(lbl_MHz6);
lbl_MHz6.setBounds(300, 110, 30, 20);
lbl_ewvcoMHz.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_ewvcoMHz.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
getContentPane().add(lbl_ewvcoMHz);
lbl_ewvcoMHz.setBounds(380, 110, 50, 20);
lbl_MHz4.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_MHz4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbl_MHz4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
getContentPane().add(lbl_MHz4);
lbl_MHz4.setBounds(400, 120, 30, 20);
lbl_ewoutMHz1.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_ewoutMHz1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
getContentPane().add(lbl_ewoutMHz1);
lbl_ewoutMHz1.setBounds(560, 90, 50, 20);
lbl_MHz7.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_MHz7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbl_MHz7.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
getContentPane().add(lbl_MHz7);
lbl_MHz7.setBounds(610, 90, 30, 20);
lbl_ewoutMHz2.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_ewoutMHz2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
getContentPane().add(lbl_ewoutMHz2);
lbl_ewoutMHz2.setBounds(560, 230, 50, 20);
lbl_MHz8.setFont(new java.awt.Font("Calibri", 0, 14));
lbl_MHz8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lbl_MHz8.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
getContentPane().add(lbl_MHz8);
lbl_MHz8.setBounds(610, 230, 30, 20);
background.setFont(new java.awt.Font("Calibri", 0, 14));
background.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication2/wk_v2.png")));
background.setMaximumSize(new java.awt.Dimension(1300, 1932));
background.setMinimumSize(new java.awt.Dimension(1200, 1932));
background.setPreferredSize(new java.awt.Dimension(1600, 1932));
getContentPane().add(background);
background.setBounds(0, 0, 1500, 1940);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
getContentPane().add(jPanel1);
jPanel1.setBounds(-20, -20, 100, 100);
pack();
}
private void cb_refdivItemStateChanged(java.awt.event.ItemEvent evt) {
refreshTextLabels();
paintComponent();
}
private void cb_postdiv2ItemStateChanged(java.awt.event.ItemEvent evt) {
refreshTextLabels();
paintComponent();
}
private void cb_fbdivItemStateChanged(java.awt.event.ItemEvent evt) {
refreshTextLabels();
paintComponent();
}
private void cb_postdiv1ItemStateChanged(java.awt.event.ItemEvent evt) {
refreshTextLabels();
paintComponent();
}
private void cb_ewiclkItemStateChanged(java.awt.event.ItemEvent evt) {
if(evt.getItem().toString().equals("FRC")){
ebypass.setSelected(true);
wbypass.setSelected(true);
lbl_epllFreq1.setText("8000000");
lbl_wpllFreq1.setText("8000000");
}
else
{
ebypass.setSelected(false);
wbypass.setSelected(false);
}
}
private void ebypassItemStateChanged(java.awt.event.ItemEvent evt) {
refreshTextLabels();
paintComponent();
}
private void wbypassItemStateChanged(java.awt.event.ItemEvent evt) {
refreshTextLabels();
paintComponent();
}
private void btn_cancelActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void btn_autoActionPerformed(java.awt.event.ActionEvent evt) {
if (cb_ewiclk.getSelectedItem().toString().contains("POSC"))
{
EWPLL_AutoCalculateDialog.main(null, (long)50000000,(long)160000000, (long)40000000, this);
}
else
{
EWPLL_AutoCalculateDialog.main(null, (long)50000000,(long)160000000, (long)8000000, this);
}
}
private void btn_applyActionPerformed(java.awt.event.ActionEvent evt) {
refreshTextLabels();
paintComponent();
}
public static void main(String args[]) {
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(Clockcycle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Clockcycle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Clockcycle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Clockcycle.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Clockcycle().setVisible(true);
}
});
}
private javax.swing.JLabel background;
private javax.swing.JButton btn_apply;
private javax.swing.JButton btn_auto;
private javax.swing.JButton btn_cancel;
private javax.swing.JComboBox<string> cb_ewiclk;
private javax.swing.JComboBox<string> cb_fbdiv;
private javax.swing.JComboBox<string> cb_postdiv1;
private javax.swing.JComboBox<string> cb_postdiv2;
private javax.swing.JComboBox<string> cb_refdiv;
private javax.swing.JCheckBox ebypass;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lbl_MHz4;
private javax.swing.JLabel lbl_MHz6;
private javax.swing.JLabel lbl_MHz7;
private javax.swing.JLabel lbl_MHz8;
private javax.swing.JLabel lbl_epllFreq1;
private javax.swing.JLabel lbl_ewinMHz;
private javax.swing.JLabel lbl_ewoutMHz1;
private javax.swing.JLabel lbl_ewoutMHz2;
private javax.swing.JLabel lbl_ewpllpostdiv1;
private javax.swing.JLabel lbl_ewpllpostdiv2;
private javax.swing.JLabel lbl_ewrefdiv;
private javax.swing.JLabel lbl_ewvcoMHz;
private javax.swing.JLabel lbl_fbdiv;
private javax.swing.JLabel lbl_fpd;
private javax.swing.JLabel lbl_fvco;
private javax.swing.JLabel lbl_refdiv;
private javax.swing.JLabel lbl_wpllFreq1;
private javax.swing.JCheckBox wbypass;
}
package javaapplication2;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.text.DecimalFormat;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
interface EWPApplyChangeListener
{
void applyEWDividerChange(int inputDivider, int multiplier, int outputDivider1, int outputDivider2);
}
public class EWPLL_AutoCalculateDialog extends javax.swing.JDialog
{
static EWPLL_AutoCalculateDialog _instance;
public static final int RET_CANCEL = 0;
public static final int RET_OK = 1;
public static EWPApplyChangeListener _applyChangeListener = null;
private long _closestFrequency = 0;
private long _inputFrequency = 0;
private int _pllidivEstimate = 0;
private int _pllodivEstimate1 = 0;
private int _pllodivEstimate2 = 0;
private int _pllmultEstimate = 0;
private double spnfreq1, spnfreq2 =0;
public EWPLL_AutoCalculateDialog(long initialTargetFrequency1, long initialTargetFrequency2, long inputFrequency, EWPApplyChangeListener listener)
{
String cancelName = "cancel";
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
ActionMap actionMap = getRootPane().getActionMap();
actionMap.put(cancelName, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
doClose(RET_CANCEL);
}
});
_inputFrequency = inputFrequency;
_closestFrequency = initialTargetFrequency1;
_applyChangeListener = listener;
System.out.println("initialTargetFrequency1"+initialTargetFrequency1);
System.out.println("initialTargetFrequency2" +initialTargetFrequency2);
spn_TargetFrequency1.setValue(initialTargetFrequency1);
lbl_spllInputFreq1.setText(String.valueOf(inputFrequency));
spn_TargetFrequency2.setValue(initialTargetFrequency2);
lbl_spllInputFreq2.setText(String.valueOf(inputFrequency));
RecalculateFreqencies1();
RecalculateFreqencies2();
}
public int getReturnStatus() {
return returnStatus;
}
@SuppressWarnings("unchecked")
private void initComponents() {
spn_TargetFrequency1 = new javax.swing.JSpinner();
btn_apply = new javax.swing.JButton();
btn_cancel = new javax.swing.JButton();
lbl_DesiredSystemFrequency = new javax.swing.JLabel();
lbl_SPLLInputFrequency = new javax.swing.JLabel();
lbl_BestAchievableFrequency = new javax.swing.JLabel();
lbl_PercentError = new javax.swing.JLabel();
lbl_Hz = new javax.swing.JLabel();
lbl_Hz3 = new javax.swing.JLabel();
lbl_Hz4 = new javax.swing.JLabel();
lbl_percentError1 = new javax.swing.JLabel();
lbl_spllInputFreq1 = new javax.swing.JLabel();
lbl_bestOutputFreq1 = new javax.swing.JLabel();
lbl_PercentSign = new javax.swing.JLabel();
lbl_DesiredSystemFrequency1 = new javax.swing.JLabel();
spn_TargetFrequency2 = new javax.swing.JSpinner();
lbl_Hz1 = new javax.swing.JLabel();
lbl_SPLLInputFrequency1 = new javax.swing.JLabel();
lbl_spllInputFreq2 = new javax.swing.JLabel();
lbl_Hz5 = new javax.swing.JLabel();
lbl_BestAchievableFrequency1 = new javax.swing.JLabel();
lbl_bestOutputFreq2 = new javax.swing.JLabel();
lbl_Hz6 = new javax.swing.JLabel();
lbl_PercentError1 = new javax.swing.JLabel();
lbl_percentError2 = new javax.swing.JLabel();
lbl_PercentSign1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Auto-Calculate EW PLL Dividers");
setName("EWAutoCalculateDialog");
setResizable(false);
spn_TargetFrequency1.setFont(new java.awt.Font("Calibri", 0, 16));
spn_TargetFrequency1.setModel(new javax.swing.SpinnerNumberModel(Long.valueOf(32000L), Long.valueOf(32000L), Long.valueOf(1000000000L), Long.valueOf(1000L)));
spn_TargetFrequency1.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spn_TargetFrequency1StateChanged(evt);
}
});
spn_TargetFrequency1.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
spn_TargetFrequency1PropertyChange(evt);
}
});
btn_apply.setFont(new java.awt.Font("Calibri", 1, 16));
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("javaapplication2/Bundle");
btn_apply.setText(bundle.getString("AutoCalculateDialog.btn_apply.text"));
btn_apply.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_applyActionPerformed(evt);
}
});
btn_cancel.setFont(new java.awt.Font("Calibri", 1, 16));
btn_cancel.setText(bundle.getString("AutoCalculateDialog.btn_cancel.text"));
btn_cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_cancelActionPerformed(evt);
}
});
lbl_DesiredSystemFrequency.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_DesiredSystemFrequency.setText(bundle.getString("AutoCalculateDialog.lbl_DesiredSystemFrequency.text"));
lbl_SPLLInputFrequency.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_SPLLInputFrequency.setText(bundle.getString("AutoCalculateDialog.lbl_SPLLInputFrequency.text"));
lbl_BestAchievableFrequency.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_BestAchievableFrequency.setText(bundle.getString("AutoCalculateDialog.lbl_BestAchievableFrequency.text"));
lbl_PercentError.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_PercentError.setText(bundle.getString("AutoCalculateDialog.lbl_PercentError.text"));
lbl_Hz.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_Hz.setText(bundle.getString("AutoCalculateDialog.lbl_Hz.text"));
lbl_Hz3.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_Hz3.setText(bundle.getString("AutoCalculateDialog.lbl_Hz3.text"));
lbl_Hz4.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_Hz4.setText(bundle.getString("AutoCalculateDialog.lbl_Hz4.text"));
lbl_percentError1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_percentError1.setText(bundle.getString("AutoCalculateDialog.lbl_percentError.text"));
lbl_spllInputFreq1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_spllInputFreq1.setText(bundle.getString("AutoCalculateDialog.lbl_spllInputFreq.text"));
lbl_bestOutputFreq1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_bestOutputFreq1.setText(bundle.getString("AutoCalculateDialog.lbl_bestOutputFreq.text"));
lbl_PercentSign.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_PercentSign.setText(bundle.getString("AutoCalculateDialog.lbl_PercentSign.text"));
lbl_DesiredSystemFrequency1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_DesiredSystemFrequency1.setText(bundle.getString("AutoCalculateDialog.lbl_DesiredSystemFrequency.text_1"));
spn_TargetFrequency2.setFont(new java.awt.Font("Calibri", 0, 16));
spn_TargetFrequency2.setModel(new javax.swing.SpinnerNumberModel(Long.valueOf(32000L), Long.valueOf(32000L), Long.valueOf(1000000000L), Long.valueOf(1000L)));
spn_TargetFrequency2.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spn_TargetFrequency2StateChanged(evt);
}
});
spn_TargetFrequency2.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
spn_TargetFrequency2PropertyChange(evt);
}
});
lbl_Hz1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_Hz1.setText(bundle.getString("AutoCalculateDialog.lbl_Hz.text_1"));
lbl_SPLLInputFrequency1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_SPLLInputFrequency1.setText(bundle.getString("AutoCalculateDialog.lbl_SPLLInputFrequency.text_1"));
lbl_spllInputFreq2.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_spllInputFreq2.setText(bundle.getString("AutoCalculateDialog.lbl_spllInputFreq.text_1"));
lbl_Hz5.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_Hz5.setText(bundle.getString("AutoCalculateDialog.lbl_Hz3.text"));
lbl_BestAchievableFrequency1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_BestAchievableFrequency1.setText(bundle.getString("AutoCalculateDialog.lbl_BestAchievableFrequency.text_1"));
lbl_bestOutputFreq2.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_bestOutputFreq2.setText(bundle.getString("AutoCalculateDialog.lbl_bestOutputFreq.text_1"));
lbl_Hz6.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_Hz6.setText(bundle.getString("AutoCalculateDialog.lbl_Hz4.text_1"));
lbl_PercentError1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_PercentError1.setText(bundle.getString("AutoCalculateDialog.lbl_PercentError.text_1"));
lbl_percentError2.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_percentError2.setText(bundle.getString("AutoCalculateDialog.lbl_percentError.text_1"));
lbl_PercentSign1.setFont(new java.awt.Font("Calibri", 0, 16));
lbl_PercentSign1.setText(bundle.getString("AutoCalculateDialog.lbl_PercentSign.text_1"));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(69, 69, 69)
.addComponent(lbl_SPLLInputFrequency, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbl_BestAchievableFrequency, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lbl_PercentError, javax.swing.GroupLayout.Alignment.TRAILING))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 130, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_bestOutputFreq1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_Hz4))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_percentError1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_PercentSign)
.addGap(4, 4, 4)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_spllInputFreq1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_Hz3))
.addGroup(layout.createSequentialGroup()
.addComponent(spn_TargetFrequency1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_Hz)))
.addGap(13, 13, 13))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btn_apply)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btn_cancel)
.addGap(14, 14, 14))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lbl_spllInputFreq2)
.addComponent(spn_TargetFrequency2, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbl_bestOutputFreq2)
.addComponent(lbl_percentError2))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(5, 5, 5)
.addComponent(lbl_Hz1))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_Hz5)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_Hz6)))
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lbl_PercentSign1)))
.addContainerGap())))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbl_DesiredSystemFrequency1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbl_DesiredSystemFrequency, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lbl_BestAchievableFrequency1)
.addComponent(lbl_SPLLInputFrequency1, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbl_PercentError1))))
.addContainerGap(240, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spn_TargetFrequency1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbl_DesiredSystemFrequency, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbl_Hz))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_SPLLInputFrequency)
.addComponent(lbl_Hz3)
.addComponent(lbl_spllInputFreq1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_BestAchievableFrequency)
.addComponent(lbl_Hz4)
.addComponent(lbl_bestOutputFreq1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_PercentError)
.addComponent(lbl_percentError1)
.addComponent(lbl_PercentSign))
.addGap(38, 38, 38)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lbl_DesiredSystemFrequency1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spn_TargetFrequency2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lbl_Hz1)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_SPLLInputFrequency1)
.addComponent(lbl_spllInputFreq2)
.addComponent(lbl_Hz5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_BestAchievableFrequency1)
.addComponent(lbl_bestOutputFreq2)
.addComponent(lbl_Hz6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_PercentError1)
.addComponent(lbl_percentError2)
.addComponent(lbl_PercentSign1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn_apply, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}
private void spn_TargetFrequency1StateChanged(javax.swing.event.ChangeEvent evt) {
RecalculateFreqencies1();
}
private void spn_TargetFrequency1PropertyChange(java.beans.PropertyChangeEvent evt) {
RecalculateFreqencies1();
}
private void btn_applyActionPerformed(java.awt.event.ActionEvent evt) {
if (_applyChangeListener != null)
{
_applyChangeListener.applyEWDividerChange(_pllidivEstimate, _pllmultEstimate, _pllodivEstimate1, _pllodivEstimate2);
}
doClose(RET_OK);
}
private void btn_cancelActionPerformed(java.awt.event.ActionEvent evt) {
}
private void spn_TargetFrequency2StateChanged(javax.swing.event.ChangeEvent evt) {
RecalculateFreqencies2();
}
private void spn_TargetFrequency2PropertyChange(java.beans.PropertyChangeEvent evt) {
RecalculateFreqencies2();
}
private void doClose(int retStatus) {
returnStatus = retStatus;
setVisible(false);
dispose();
}
public static void main(String args[], final long initialTargetFrequency1,final long initialTargetFrequency2, final long inputFrequency, final EWPApplyChangeListener listener ) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
System.out.println("listener==" +listener.toString());
System.out.println("initialTargetFrequency1==" +initialTargetFrequency1);
System.out.println("initialTargetFrequency2==" +initialTargetFrequency2);
System.out.println("inputFrequency==" +inputFrequency);
_instance = new EWPLL_AutoCalculateDialog(initialTargetFrequency1, initialTargetFrequency2, inputFrequency, listener);
_instance.addWindowListener(new java.awt.event.WindowAdapter()
{
@Override
public void windowClosing(java.awt.event.WindowEvent e)
{
System.exit(0);
}
});
_instance.setVisible(true);
}
});
}
public static EWPLL_AutoCalculateDialog instance()
{
return _instance;
}
private void RecalculateFreqencies1()
{
int inputDivider = 0;
int outputDivider1 = 0;
int outputDivider2 = 0;
int multiplier = 0;
double tempFrequency1 = 0.f;
double tempFrequency2 = 0.f;
double closestFrequency1 = 0.f;
double closestFrequency2 = 0.f;
long targetFrequencyLong1 = (long)spn_TargetFrequency1.getValue();
long targetFrequencyLong2 = (long)spn_TargetFrequency2.getValue();
double targetFrequency1 = (double)targetFrequencyLong1;
double targetFrequency2 = (double)targetFrequencyLong2;
DecimalFormat twoDecimalFormat = new DecimalFormat("###,###,###.##");
DecimalFormat singleDecimalFormat = new DecimalFormat("#.#####");
if(targetFrequencyLong1== 50000000)
{
tempFrequency1 = ((( (double)_inputFrequency / (double) 20 ) * (double) 800) / (double) 32);
closestFrequency1 = tempFrequency1;
_pllidivEstimate = 20;
_pllodivEstimate1 = 32;
_pllmultEstimate = 800;
_pllodivEstimate2 = 10;
spn_TargetFrequency2.setValue(160000000);
}
else
{
for (int iDiv = 1; iDiv <= 63; ++iDiv)
{
inputDivider = iDiv;
for (int mult = 16; mult <= 1023; ++mult)
{
multiplier = mult;
for (int oDiv = 0; oDiv <= 63; ++oDiv)
{
if (oDiv == 0 || oDiv == 1)
{
outputDivider1 = 2;
}
else
{
outputDivider1 = 0x01 << oDiv;
}
tempFrequency1 = ( (double)_inputFrequency / (double) inputDivider ) * (double) multiplier / (double) outputDivider1;
double Fin = (double)_inputFrequency / (double) inputDivider;
double Fvco = Fin * (double)multiplier;
if ( closestFrequency1 == 0 || Math.abs( targetFrequency1 - tempFrequency1 ) < Math.abs( targetFrequency1 - closestFrequency1))
{
if (Fin >= 5000000 && Fin <= 64000000 && Fvco >= 800000000 && Fvco <= 1600000000
&& tempFrequency1 >= 10000000 && tempFrequency1 <= 200000000)
{
closestFrequency1 = tempFrequency1;
_pllidivEstimate = inputDivider;
_pllodivEstimate1 = outputDivider1;
_pllmultEstimate = multiplier;
}
}
}
}
}
}
double percentError1 = Math.abs(closestFrequency1 - targetFrequency1) / targetFrequency1 * 100.f;
lbl_bestOutputFreq1.setText(String.valueOf((long)closestFrequency1));
lbl_percentError1.setText(singleDecimalFormat.format(percentError1));
double outputspn2 = _pllodivEstimate1/3;
if (outputspn2<1)
outputspn2 = 1;
spnfreq2 = ( (double)_inputFrequency / (double) _pllidivEstimate ) * (double) _pllodivEstimate1 / (double)outputspn2;
spn_TargetFrequency2.setValue(spnfreq2);
}
private void RecalculateFreqencies2()
{
int inputDivider = 0;
int outputDivider1 = 0;
int outputDivider2 = 0;
int multiplier = 0;
double tempFrequency1 = 0.f;
double tempFrequency2 = 0.f;
double closestFrequency1 = 0.f;
double closestFrequency2 = 0.f;
long targetFrequencyLong1 = (long)spn_TargetFrequency1.getValue();
long targetFrequencyLong2 = (long)spn_TargetFrequency2.getValue();
double targetFrequency1 = (double)targetFrequencyLong1;
double targetFrequency2 = (double)targetFrequencyLong2;
DecimalFormat twoDecimalFormat = new DecimalFormat("###,###,###.##");
DecimalFormat singleDecimalFormat = new DecimalFormat("#.#####");
if(targetFrequencyLong2==160000000)
{
tempFrequency2 = ((( (double)_inputFrequency / (double) 20 ) * (double) 800) / (double) 10);
closestFrequency2 = tempFrequency2;
_pllidivEstimate = 20;
_pllodivEstimate1 = 32;
_pllmultEstimate = 800;
_pllodivEstimate2 = 10;
spn_TargetFrequency1.setValue(50000000);
}
else
{
for (int iDiv = 1; iDiv <= 63; ++iDiv)
{
inputDivider = iDiv;
for (int mult = 16; mult <= 1023; ++mult)
{
multiplier = mult;
for (int oDiv = 0; oDiv <= 63; ++oDiv)
{
if (oDiv == 0 || oDiv == 1)
{
outputDivider2 = 2;
}
else
{
outputDivider2 = 0x01 << oDiv;
}
tempFrequency2 = ( (double)_inputFrequency / (double) inputDivider ) * (double) multiplier / (double) outputDivider2;
double Fin = (double)_inputFrequency / (double) inputDivider;
double Fvco = Fin * (double)multiplier;
if ( closestFrequency2 == 0 || Math.abs( targetFrequency2 - tempFrequency2 ) < Math.abs( targetFrequency2 - closestFrequency2))
{
if (Fin >= 5000000 && Fin <= 64000000 && Fvco >= 800000000 && Fvco <= 1600000000
&& tempFrequency1 >= 10000000 && tempFrequency1 <= 200000000)
{
closestFrequency1 = tempFrequency1;
_pllidivEstimate = inputDivider;
_pllodivEstimate2 = outputDivider2;
_pllmultEstimate = multiplier;
}
}
}
}
}
}
double percentError2 = Math.abs(closestFrequency2 - targetFrequency2) / targetFrequency2 * 100.f;
lbl_bestOutputFreq2.setText(String.valueOf((long)closestFrequency1));
lbl_percentError2.setText(singleDecimalFormat.format(percentError2));
double outputspn1 = _pllodivEstimate1*3;
if (outputspn1 > 63)
outputspn1 = 63;
spnfreq1 = ( (double)_inputFrequency / (double) _pllidivEstimate ) * (double) _pllodivEstimate1 / (double)outputspn1;
spn_TargetFrequency1.setValue(spnfreq1);
}
public void setInitialSettings1(long initialTargetFrequency1, long inputFrequency)
{
spn_TargetFrequency1.setValue(initialTargetFrequency1);
_inputFrequency = inputFrequency;
lbl_spllInputFreq1.setText(String.valueOf(inputFrequency));
RecalculateFreqencies1();
}
public void setInitialSettings2(long initialTargetFrequency2, long inputFrequency)
{
spn_TargetFrequency2.setValue(initialTargetFrequency2);
_inputFrequency = inputFrequency;
lbl_spllInputFreq2.setText(String.valueOf(inputFrequency));
RecalculateFreqencies2();
}
private javax.swing.JButton btn_apply;
private javax.swing.JButton btn_cancel;
private javax.swing.JLabel lbl_BestAchievableFrequency;
private javax.swing.JLabel lbl_BestAchievableFrequency1;
private javax.swing.JLabel lbl_DesiredSystemFrequency;
private javax.swing.JLabel lbl_DesiredSystemFrequency1;
private javax.swing.JLabel lbl_Hz;
private javax.swing.JLabel lbl_Hz1;
private javax.swing.JLabel lbl_Hz3;
private javax.swing.JLabel lbl_Hz4;
private javax.swing.JLabel lbl_Hz5;
private javax.swing.JLabel lbl_Hz6;
private javax.swing.JLabel lbl_PercentError;
private javax.swing.JLabel lbl_PercentError1;
private javax.swing.JLabel lbl_PercentSign;
private javax.swing.JLabel lbl_PercentSign1;
private javax.swing.JLabel lbl_SPLLInputFrequency;
private javax.swing.JLabel lbl_SPLLInputFrequency1;
private javax.swing.JLabel lbl_bestOutputFreq1;
private javax.swing.JLabel lbl_bestOutputFreq2;
private javax.swing.JLabel lbl_percentError1;
private javax.swing.JLabel lbl_percentError2;
private javax.swing.JLabel lbl_spllInputFreq1;
private javax.swing.JLabel lbl_spllInputFreq2;
private javax.swing.JSpinner spn_TargetFrequency1;
private javax.swing.JSpinner spn_TargetFrequency2;
private int returnStatus = RET_CANCEL;
}
What I have tried:
I tried checking where null coming from. I think its problem with the listener.