Results 1 to 9 of 9
Like Tree2Likes
  • 2 Post By Prime624

Thread: What is wrong with my code?

  1. #1
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default What is wrong with my code?

    Java Code:
    package programtesisbaru;
    
    
    import java.awt.*;
    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    /**
    *
    * @author Tawi
    */
    public class ProgramTesisBaru extends JFrame{
    Container konten = getContentPane();
    private JLabel lblNama = new JLabel("Nama : ");
    private JTextField txtNama = new JTextField();
    private JLabel kataSandi = new JLabel("Kata Sandi : ");
    private JPasswordField sandiKata = new JPasswordField();
    private JButton masuk = new JButton("Masuk");
    private JButton keluar = new JButton("Keluar");
    int i;
    JButton tombolHubungkankePadukData = new JButton("Hubungkan ke Paduk Data");
    JButton putuskanKoneksiKePadukData = new JButton("Putuskan Koneksi ke Paduk Data");
    JButton tombolUbahPadukData = new JButton("Ubah Paduk Data");
    JButton tombolBatal = new JButton("Batal");
    JButton lanjut = new JButton("Lanjut");
    JComboBox jcboURL = new JComboBox (new String[] {"jdbc:odbc:DatabaseKlinik"});
    JComboBox jcboDriver = new JComboBox (new String[] {"sun.jdbc.odbc.JdbcOdbcDriver"});
    private Connection connection;
    private Statement statement;
    JLabel statusKoneksi = new JLabel("Tidak ada Koneksi ke Paduk Data");
    JLabel padukData = new JLabel("Paduk Data Belum Diubah");
    String namaPengguna1;
    String passwordPengguna1;
    JLabel myocardialInfarction = new JLabel("Myocardial Infarction");
    JLabel stroke = new JLabel("Stroke");
    JLabel[][] kriteria = new JLabel[4][2];
    //JLabel kriteriaa = new JLabel("Kriteria 1");
    //JLabel kriteriab = new JLabel("Kriteria 2");
    //JLabel kriteriac = new JLabel("Kriteria 3");
    //JLabel kriteriad = new JLabel("Kriteria 4");
    JLabel[][] alternatif = new JLabel[5][2];
    //JLabel alternatifa = new JLabel("Alternatif 1");
    //JLabel alternatifb = new JLabel("Alternatif 2");
    //JLabel alternatifc = new JLabel("Alternatif 3");
    //JLabel alternatifd = new JLabel("Alternatif 4");
    //JLabel alternatife = new JLabel("Alternatif 5");
    JTextField[][]jawabKriteria = new JTextField [4][2];
    JTextField[][] jawabAlternatif = new JTextField[5][2];
    JLabel statusMasuk = new JLabel("Belum Masuk");
    String ax = "Nama Dokter Belum Dimasukkan"; 
    String bx = "Dokter atau Kata Sandi tidak Ada";
    String cx = "Kata Sandi Belum Dimasukkan";
    String dx = "Nama Dokter Belum Dimasukkan";
    String ex = "Dokter tidak Dikenal";
    String fx = "Kata Kunci tidak Benar";
    String gx = "Nama Pengguna dan Kata Kunci tidak Benar";
    String hx = "Nama Dokter dan Kata Sandi tidak Ada";
    
    public ProgramTesisBaru()
    { 
    konten.setLayout(null);
    // Atur letak beberapa komponen
    for (int tlo = 0; tlo < 2; tlo++)
    {
    kriteria[0][tlo].setText("Kriteria 1");
    kriteria[1][tlo].setText("Kriteria 2");
    kriteria[2][tlo].setText("Kriteria 3");
    kriteria[3][tlo].setText("Kriteria 4");
    alternatif[0][tlo].setText("Alternatif 1");
    alternatif[1][tlo].setText("Alternatif 2");
    alternatif[2][tlo].setText("Alternatif 3");
    alternatif[3][tlo].setText("Alternatif 4");
    alternatif[4][tlo].setText("Alternatif 5");
    }
    lblNama.setBounds(0,10,100,25);
    konten.add(lblNama);
    txtNama.setBounds(130,10,200,25);
    konten.add(txtNama);
    kataSandi.setBounds(330,10,100,25);
    konten.add(kataSandi);
    sandiKata.setBounds(410,10,200,25);
    konten.add(sandiKata);
    masuk.setBounds(600,10,100,25);
    konten.add(masuk);
    keluar.setBounds(700,10,100,25);
    konten.add(keluar);
    tombolHubungkankePadukData.setBounds(0,50,250,25);
    konten.add(tombolHubungkankePadukData);
    putuskanKoneksiKePadukData.setBounds(250,50,250,25);
    konten.add(putuskanKoneksiKePadukData);
    tombolUbahPadukData.setBounds(480,50,250,25);
    konten.add(tombolUbahPadukData);
    tombolBatal.setBounds(730,50,250,25);
    konten.add(tombolBatal);
    statusKoneksi.setBounds(800,10,200,25);
    konten.add(statusKoneksi);
    padukData.setBounds(0,70,200,25);
    statusMasuk.setBounds(160,70,200,25);
    myocardialInfarction.setBounds(0,120,200,25);
    konten.add(myocardialInfarction);
    konten.add(padukData);
    tombolHubungkankePadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    for (int jwbKri = 0; jwbKri < 4; jwbKri++)
    {
    jawabKriteria[jwbKri][0] = new JTextField(10);
    jawabKriteria[jwbKri][1] = new JTextField(10);
    }
    for (int jwbAlt = 0; jwbAlt < 5; jwbAlt++)
    {
    jawabAlternatif[jwbAlt][0] = new JTextField(10);
    jawabAlternatif[jwbAlt][1] = new JTextField(10);
    }
    lanjut.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    kontinu();
    }
    private void kontinu() {
    FrameBaru baru = new FrameBaru(); // I want to make a class that is named FrameBaru to be visible
    }
    });
    tombolUbahPadukData.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    ubah();
    }
    
    private void ubah() {
    for (int lmo = 0; lmo < 4; lmo++)
    {
    jawabKriteria[lmo][0].setEditable(true);
    }
    for (int mlo = 0; mlo < 5; mlo++)
    {
    jawabAlternatif[mlo][0].setEditable(true);
    jawabAlternatif[mlo][1].setEditable(true);
    }
    lanjut.setEnabled(true);
    }
    });
    putuskanKoneksiKePadukData.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    try {
    putuskan();
    } catch (SQLException ex) {
    Logger.getLogger(ProgramTesisBaru.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    
    private void putuskan() throws SQLException {
    if (connection == null)
    {
    statusKoneksi.setText("Tidak ada Koneksi ke Paduk Data");
    for (int ltu = 0; ltu < 4; ltu++)
    {
    jawabKriteria[ltu][0].setEditable(false);
    jawabKriteria[ltu][1].setEditable(false);
    }
    for (int tlu = 0; tlu < 5; tlu++)
    {
    jawabAlternatif[tlu][0].setEditable(false);
    jawabAlternatif[tlu][1].setEditable(false);
    }
    }
    else 
    {
    connection.close();
    statusKoneksi.setText("Tidak ada Koneksi ke Paduk Data");
    for (int lko = 0; lko < 4; lko++)
    {
    jawabKriteria[lko][0].setEditable(false);
    jawabKriteria[lko][1].setEditable(false);
    }
    for (int lok = 0; lok < 5; lok++)
    {
    jawabAlternatif[lok][0].setEditable(false);
    jawabAlternatif[lok][1].setEditable(false);
    }                
    }
    }
    });
    masuk.addActionListener(new java.awt.event.ActionListener() {
    private String loginName;
    private String loginPassword;
    private String usrname;
    private String psswrd;
    private String passwrd;
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    try {
    masuklah();
    } 
    catch (SQLException ex) {
    Logger.getLogger(ProgramTesisBaru.class.getName()).log(Level.SEVERE, null, ex);
    }
    }
    
    private void masuklah() throws SQLException {
    if (connection == null)
    {
    masuk.setEnabled(false);
    connectToDB();
    entryPrg();
    }
    else {
    entryPrg();
    }
    }
    
    public void connectToDB() {
    String uniRL = (String)jcboURL.getSelectedItem();
    String driver = (String) jcboDriver.getSelectedItem();
    //URL uniRL = (URL)jcboURL.getSelectedItem();
    usrname = txtNama.getText().trim();
    passwrd = new String(sandiKata.getPassword());
    try {
    Class.forName(driver);
    connection = DriverManager.getConnection(uniRL, usrname, passwrd);
    //rowSet.setURL(uniRL);
    statusKoneksi.setText("Terhubung ke Paduk Data");
    }
    catch (ClassNotFoundException | SQLException ex) {
    statusKoneksi.setText("Gagal Terhubung ke Paduk Data");
    }
    }
    
    private void entryPrg() throws SQLException {
    usrname = txtNama.getText().trim();
    psswrd = new String(sandiKata.getPassword());
    loginName = "select Nama_Dokter from tblDokterNaraSumber where Nama_Dokter = '"+usrname+"'";
    loginPassword = "select Password from tblDokterNaraSumber where Nama_Dokter = '"+usrname+"'";
    try {
    ResultSet logName = statement.executeQuery(loginName);
    ResultSet logPassword = statement.executeQuery(loginPassword);
    while (logName.next()) {
    namaPengguna1 = logName.getString("Nama_Dokter");
    }
    while (logPassword.next()) {
    passwordPengguna1 = logPassword.getString("Password");
    }
    }
    catch (java.lang.Exception ex){
    statusMasuk.setText("Gagal Masuk");
    }
    if ("".equals(usrname) && "".equals(psswrd)) 
    {
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    JOptionPane.showMessageDialog(null, gx, hx, JOptionPane.INFORMATION_MESSAGE);
    }
    else if ((!"".equals(usrname)) && (!"".equals(psswrd)))
    {
    if ((!"".equals(namaPengguna1)) && (!"".equals(passwordPengguna1))) 
    {
    tombolHubungkankePadukData.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(true);
    tombolUbahPadukData.setEnabled(true);
    tombolBatal.setEnabled(true);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(true);
    connection.close();
    }
    else if ((!"".equals(namaPengguna1)))
    {
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    JOptionPane.showMessageDialog(null, fx, bx, JOptionPane.INFORMATION_MESSAGE);
    connection.close();
    }
    else if (passwordPengguna1 != null)
    {
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    JOptionPane.showMessageDialog(null, ex, bx, JOptionPane.INFORMATION_MESSAGE);
    connection.close();
    }
    }
    else if (!"".equals(usrname))
    {
    if (("".equals(namaPengguna1)) && ("".equals(passwordPengguna1))) 
    {
    JOptionPane.showMessageDialog(null, cx, bx, JOptionPane.INFORMATION_MESSAGE);
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    connection.close();                        
    }
    else if (("".equals(namaPengguna1)))
    {
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    JOptionPane.showMessageDialog(null, cx, bx, JOptionPane.INFORMATION_MESSAGE);              
    connection.close();                        
    }
    else if (passwordPengguna1 == null)
    {
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    JOptionPane.showMessageDialog(null, cx, bx, JOptionPane.INFORMATION_MESSAGE);                        
    connection.close();                        
    }
    }
    else if (!"".equals(psswrd))
    {
    if (("".equals(namaPengguna1)) && ("".equals(passwordPengguna1))) 
    {
    JOptionPane.showMessageDialog(null, dx, bx, JOptionPane.INFORMATION_MESSAGE);
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);                        
    connection.close();                        
    }
    else if (("".equals(namaPengguna1)))
    {
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    JOptionPane.showMessageDialog(null, dx, bx, JOptionPane.INFORMATION_MESSAGE);                        
    connection.close();                        
    }
    else if (passwordPengguna1 == null)
    {
    tombolHubungkankePadukData.setEnabled(false);
    putuskanKoneksiKePadukData.setEnabled(false);
    tombolUbahPadukData.setEnabled(false);
    tombolBatal.setEnabled(false);
    keluar.setEnabled(true);
    putuskanKoneksiKePadukData.setEnabled(false);
    JOptionPane.showMessageDialog(null, dx, bx, JOptionPane.INFORMATION_MESSAGE);                        
    connection.close();                        
    }
    }
    }
    });
    
    keluar.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    keluar();
    }
    
    private void keluar() {
    System.exit(0);
    }
    });
    tombolBatal.addActionListener(new java.awt.event.ActionListener() {
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    batal();
    }
    
    private void batal() {
    for (int k = 0; k < 4; k++)
    {
    jawabKriteria[k][0].setText("");
    jawabKriteria[k][1].setText("");
    }
    for (int lkm = 0; lkm < 5; lkm++)
    {
    jawabAlternatif[lkm][0].setText("");
    jawabAlternatif[lkm][1].setText("");
    }
    for (int lqj = 0; lqj < 4; lqj++)
    {
    jawabKriteria[lqj][0].setEditable(false);
    jawabKriteria[lqj][1].setEditable(false);
    }
    for (int ljq = 0; ljq < 5; ljq++)
    {
    jawabAlternatif[ljq][0].setEditable(false);
    jawabAlternatif[ljq][1].setEditable(false);
    }
    lanjut.setEnabled(false);
    }
    });
    tombolHubungkankePadukData.addActionListener(new java.awt.event.ActionListener() {
    private String usrname;
    private String passwrd;
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    if (connection == null)
    {
    connectToDB();
    statusKoneksi.setText("Terhubung ke Paduk Data");
    }
    else
    {
    statusKoneksi.setText("Sudah Terhubung ke Paduk Data");
    }
    }
    
    private void connectToDB() {
    String uniRL = "jdbc:odbc:DatabaseKlinik";
    //URL uniRL = (URL)jcboURL.getSelectedItem();
    usrname = txtNama.getText().trim();
    passwrd = new String(sandiKata.getPassword());
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    connection = DriverManager.getConnection(uniRL, usrname, passwrd);
    //rowSet.setURL(uniRL);
    statusKoneksi.setText("Terhubung ke Paduk Data");
    }
    catch (ClassNotFoundException | SQLException ex) {
    statusKoneksi.setText("Gagal Terhubung ke Paduk Data");
    }
    }
    });
    for (int m = 0; m <5; m++)
    {
    jawabAlternatif[m][0].setEditable(false);
    jawabAlternatif[m][1].setEditable(false);
    }
    for (int hki = 0; hki < 4; hki++)
    {
    jawabKriteria[hki][0].setEditable(false);
    jawabKriteria[hki][1].setEditable(false);
    }
    // Tanda Alternatif Harga Myocardial Infarction
    kriteria[0][0].setBounds(1,200,100,25);
    kriteria[1][0].setBounds(1,230,100,25);
    kriteria[2][0].setBounds(1,260,100,25);
    kriteria[3][0].setBounds(1,290,100,25);
    for (int lop = 0; lop < 4; lop++)
    {
    konten.add(kriteria[lop][0]);
    }
    // Alternatif Sakit Harga Myocardial Infarction
    jawabKriteria[0][0].setBounds(101,200,70,25);
    jawabKriteria[1][0].setBounds(101,230,70,25);
    jawabKriteria[2][0].setBounds(101,260,70,25);
    jawabKriteria[3][0].setBounds(101,290,70,25);
    for (int jki = 0; jki < 4; jki++)
    {
    konten.add(jawabKriteria[jki][0]);
    }
    // Kriteria Sakit Myocardial Infarction
    alternatif[0][0].setBounds(160,200,100,25);
    alternatif[1][0].setBounds(160,230,100,25);
    alternatif[2][0].setBounds(160,260,100,25);
    alternatif[3][0].setBounds(160,290,100,25);
    alternatif[4][0].setBounds(160,320,100,25);
    for (int loyo = 0; loyo < 4; loyo++)
    {
    konten.add(alternatif[loyo][0]);
    }
    jawabAlternatif[0][0].setBounds(260,200,70,25);
    jawabAlternatif[1][0].setBounds(260,230,70,25);
    jawabAlternatif[2][0].setBounds(260,260,70,25);
    jawabAlternatif[3][0].setBounds(260,290,70,25);
    jawabAlternatif[4][0].setBounds(260,320,70,25);
    for (int gfk = 0; gfk < 5; gfk++)
    {
    konten.add(jawabAlternatif[gfk][0]);
    }
    // Awal Stroke
    stroke.setBounds(0,380,200,25);
    konten.add(stroke);
    // Tanda Kriteria Stroke
    kriteria[0][1].setBounds(1,420,200,25);
    kriteria[1][1].setBounds(1,450,200,25);
    kriteria[2][1].setBounds(1,480,200,25);
    kriteria[3][1].setBounds(1,510,200,25);
    for (int gdu = 0; gdu < 4; gdu++)
    {
    konten.add(kriteria[gdu][1]);
    }
    // Kriteria Sakit Stroke
    jawabKriteria[0][1].setBounds(101,420,60,25);
    jawabKriteria[1][1].setBounds(101,450,60,25);
    jawabKriteria[2][1].setBounds(101,480,60,25);
    jawabKriteria[3][1].setBounds(101,510,60,25);
    for (int jku = 0; jku < 4; jku++)
    {
    konten.add(jawabKriteria[jku][1]);
    }
    alternatif[0][1].setBounds(160,200,100,25);
    alternatif[1][1].setBounds(160,230,100,25);
    alternatif[2][1].setBounds(160,260,100,25);
    alternatif[3][1].setBounds(160,290,100,25);
    alternatif[4][1].setBounds(160,320,100,25);
    for (int loyom = 0; loyom < 4; loyom++)
    {
    konten.add(alternatif[loyom][1]);
    }
    jawabAlternatif[0][1].setBounds(260,200,70,25);
    jawabAlternatif[1][1].setBounds(260,230,70,25);
    jawabAlternatif[2][1].setBounds(260,260,70,25);
    jawabAlternatif[3][1].setBounds(260,290,70,25);
    jawabAlternatif[4][1].setBounds(260,320,70,25);
    for (int gfki = 0; gfki < 5; gfki++)
    {
    konten.add(jawabAlternatif[gfki][1]);
    }
    lanjut.setBounds(880,560,100,25);
    konten.add(lanjut);
    lanjut.setEnabled(false);
    
    } //Akhir Konstruktor
    
    public static void main(String[] args)
    {
    ProgramTesisBaru tesis = new ProgramTesisBaru(); 
    tesis.setTitle("Program Pemilihan Obat dengan Cara Analytic Hierarchycal Process");
    tesis.setSize(1024,768);
    tesis.setVisible(true);
    tesis.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tesis.setLocationRelativeTo(null);
    }}
    
    class FrameBaru extends JFrame {
    //ProgramTesisBaru tesis = new ProgramTesisBaru();
    JLabel alternatifHargaMyo1 = new JLabel("Nilai Alternatif Utama Harga Myocardial Infarction :");
    JLabel alternatifHargaMyo2 = new JLabel("Nilai Alternatif 2 Harga Myocardial Infarction :");
    JLabel alternatifHargaMyo3 = new JLabel("Nilai Alternatif 3 Harga Myocardial Infarction :");
    JLabel alternatifHargaMyo4 = new JLabel("Nilai Alternatif 4 Harga Myocardial Infarction :");
    JLabel alternatifHargaMyo5 = new JLabel("Nilai Alternatif 5 Harga Myocardial Infarction :");
    JLabel alternatifEfekSampingMyo1 = new JLabel("Nilai Alternatif Utama Efek Samping Myocardial Infarction :");
    JLabel alternatifEfekSampingMyo2 = new JLabel("Nilai Alternatif 2 Efek Samping Myocardial Infarction :");
    JLabel alternatifEfekSampingMyo3 = new JLabel("Nilai Alternatif 3 Efek Samping Myocardial Infarction :");
    JLabel alternatifEfekSampingMyo4 = new JLabel("Nilai Alternatif 4 Efek Samping Myocardial Infarction :");
    JLabel alternatifEfekSampingMyo5 = new JLabel("Nilai Alternatif 5 Efek Samping Myocardial Infarction :");
    JLabel alternatifKualitasMyo1 = new JLabel("Nilai Alternatif Utama Kualitas Myocardial Infarction :");
    JLabel alternatifKualitasMyo2 = new JLabel("Nilai Alternatif 2 Kualitas Myocardial Infarction :");
    JLabel alternatifKualitasMyo3 = new JLabel("Nilai Alternatif 3 Kualitas Myocardial Infarction :");
    JLabel alternatifKualitasMyo4 = new JLabel("Nilai Alternatif 4 Kualitas Myocardial Infarction :");
    JLabel alternatifKualitasMyo5 = new JLabel("Nilai Alternatif 5 Kualitas Myocardial Infarction :");
    JLabel alternatifKetersediaanMyo1 = new JLabel("Nilai Alternatif Utama Ketersediaan Myocardial Infarction :");
    JLabel alternatifKetersediaanMyo2 = new JLabel("Nilai Alternatif 2 Ketersediaan Myocardial Infarction :");
    JLabel alternatifKetersediaanMyo3 = new JLabel("Nilai Alternatif 3 Ketersediaan Myocardial Infarction :");
    JLabel alternatifKetersediaanMyo4 = new JLabel("Nilai Alternatif 4 Ketersediaan Myocardial Infarction :");
    JLabel alternatifKetersediaanMyo5 = new JLabel("Nilai Alternatif 5 Ketersediaan Myocardial Infarction :");
    JLabel alternatifHargaStroke1 = new JLabel("Nilai Alternatif Utama Harga Stroke :");
    JLabel alternatifHargaStroke2 = new JLabel("Nilai Alternatif 2 Harga Stroke :");
    JLabel alternatifHargaStroke3 = new JLabel("Nilai Alternatif 3 Harga Stroke :");
    JLabel alternatifHargaStroke4 = new JLabel("Nilai Alternatif 4 Harga Stroke :");
    JLabel alternatifHargaStroke5 = new JLabel("Nilai Alternatif 5 Harga Stroke :");
    JLabel alternatifEfekSampingStroke1 = new JLabel("Nilai Alternatif Utama Efek Samping Stroke :");
    JLabel alternatifEfekSampingStroke2 = new JLabel("Nilai Alternatif 2 Efek Samping Stroke :");
    JLabel alternatifEfekSampingStroke3 = new JLabel("Nilai Alternatif 3 Efek Samping Stroke :");
    JLabel alternatifEfekSampingStroke4 = new JLabel("Nilai Alternatif 4 Efek Samping Stroke :");
    JLabel alternatifEfekSampingStroke5 = new JLabel("Nilai Alternatif 5 Efek Samping Stroke :");
    JLabel alternatifKualitasStroke1 = new JLabel("Nilai Alternatif Utama Kualitas Stroke :");
    JLabel alternatifKualitasStroke2 = new JLabel("Nilai Alternatif 2 Kualitas Stroke :");
    JLabel alternatifKualitasStroke3 = new JLabel("Nilai Alternatif 3 Kualitas Stroke :");
    JLabel alternatifKualitasStroke4 = new JLabel("Nilai Alternatif 4 Kualitas Stroke :");
    JLabel alternatifKualitasStroke5 = new JLabel("Nilai Alternatif 5 Kualitas Stroke :");
    JLabel alternatifKetersediaanStroke1 = new JLabel("Nilai Alternatif Utama Ketersediaan Stroke :");
    JLabel alternatifKetersediaanStroke2 = new JLabel("Nilai Alternatif 2 Ketersediaan Stroke :");
    JLabel alternatifKetersediaanStroke3 = new JLabel("Nilai Alternatif 3 Ketersediaan Stroke :");
    JLabel alternatifKetersediaanStroke4 = new JLabel("Nilai Alternatif 4 Ketersediaan Stroke :");
    JLabel alternatifKetersediaanStroke5 = new JLabel("Nilai Alternatif 5 Ketersediaan Stroke :");
    JButton ubah = new JButton("Ubah Paduk Data");
    JButton kembali = new JButton("Kembali ke Menu Utama");
    JLabel myocardInfarc = new JLabel("Myocardial Infarction");
    JLabel stroke1 = new JLabel("Stroke");
    JTextField[][] jawab = new JTextField[20][2];
    
    public FrameBaru() {
    setTitle("Masukkan Hasil Analytic Hierarchical Process");
    setSize(1024,768);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);
    
    Container isi = getContentPane();
    isi.setLayout(null);
    for (int ijk = 0; ijk < jawab.length; ijk++) {  
    for (int ikj = 0; ikj < jawab[ijk].length; ikj++) {  
    jawab[ijk][ikj] = new JTextField();  
    }  
    }  
    myocardInfarc.setBounds(0,0,200,25);
    alternatifHargaMyo1.setBounds(0,50,200,25);
    alternatifHargaMyo2.setBounds(0,80,200,25);
    alternatifHargaMyo3.setBounds(0,110,200,25);
    alternatifHargaMyo4.setBounds(0,140,200,25);
    alternatifHargaMyo5.setBounds(0,170,200,25);
    jawab[0][0].setBounds(200,50,50,25);
    jawab[1][0].setBounds(200,80,50,25);
    jawab[2][0].setBounds(200,110,50,25);
    jawab[3][0].setBounds(200,140,50,25);
    jawab[4][0].setBounds(200,170,50,25);
    alternatifEfekSampingMyo1.setBounds(250,50,200,25);
    alternatifEfekSampingMyo2.setBounds(250,80,200,25);
    alternatifEfekSampingMyo3.setBounds(250,110,200,25);
    alternatifEfekSampingMyo4.setBounds(250,140,200,25);
    alternatifEfekSampingMyo5.setBounds(250,170,200,25);
    jawab[5][0].setBounds(450,50,50,25);
    jawab[6][0].setBounds(450,80,50,25);
    jawab[7][0].setBounds(450,110,50,25);
    jawab[8][0].setBounds(450,140,50,25);
    jawab[9][0].setBounds(450,170,50,25);
    alternatifKualitasMyo1.setBounds(500,50,200,25);
    alternatifKualitasMyo2.setBounds(500,80,200,25);
    alternatifKualitasMyo3.setBounds(500,110,200,25);
    alternatifKualitasMyo4.setBounds(500,140,200,25);
    alternatifKualitasMyo5.setBounds(500,170,200,25);
    jawab[10][0].setBounds(700,50,50,25);
    jawab[11][0].setBounds(700,80,50,25);
    jawab[12][0].setBounds(700,110,50,25);
    jawab[13][0].setBounds(700,140,50,25);
    jawab[14][0].setBounds(700,170,50,25);
    alternatifKetersediaanMyo1.setBounds(750,50,200,25);
    alternatifKetersediaanMyo2.setBounds(750,80,200,25);
    alternatifKetersediaanMyo3.setBounds(750,110,200,25);
    alternatifKetersediaanMyo4.setBounds(750,140,200,25);
    alternatifKetersediaanMyo5.setBounds(750,170,200,25);
    jawab[15][0].setBounds(950,50,50,25);
    jawab[16][0].setBounds(950,80,50,25);
    jawab[17][0].setBounds(950,110,50,25);
    jawab[18][0].setBounds(950,140,50,25);
    jawab[19][0].setBounds(950,170,50,25);
    isi.add(myocardInfarc);
    isi.add(alternatifHargaMyo1);
    isi.add(alternatifHargaMyo2);
    isi.add(alternatifHargaMyo3);
    isi.add(alternatifHargaMyo4);
    isi.add(alternatifHargaMyo5);
    isi.add(alternatifEfekSampingMyo1);
    isi.add(alternatifEfekSampingMyo2);
    isi.add(alternatifEfekSampingMyo3);
    isi.add(alternatifEfekSampingMyo4);
    isi.add(alternatifEfekSampingMyo5);
    isi.add(alternatifKualitasMyo1);
    isi.add(alternatifKualitasMyo2);
    isi.add(alternatifKualitasMyo3);
    isi.add(alternatifKualitasMyo4);
    isi.add(alternatifKualitasMyo5);
    isi.add(alternatifKetersediaanMyo1);
    isi.add(alternatifKetersediaanMyo2);
    isi.add(alternatifKetersediaanMyo3);
    isi.add(alternatifKetersediaanMyo4);
    isi.add(alternatifKetersediaanMyo5);
    for (int s = 0; s < 20; s++)
    {
    isi.add(jawab[s][0]);
    }
    stroke1.setBounds(0,250,200,25);
    alternatifHargaStroke1.setBounds(0,300,200,25);
    alternatifHargaStroke2.setBounds(0,330,200,25);
    alternatifHargaStroke3.setBounds(0,360,200,25);
    alternatifHargaStroke4.setBounds(0,390,200,25);
    alternatifHargaStroke5.setBounds(0,420,200,25);
    jawab[0][1].setBounds(200,300,50,25);
    jawab[1][1].setBounds(200,330,50,25);
    jawab[2][1].setBounds(200,360,50,25);
    jawab[3][1].setBounds(200,390,50,25);
    jawab[4][1].setBounds(200,420,50,25);
    alternatifEfekSampingStroke1.setBounds(250,300,200,25);
    alternatifEfekSampingStroke2.setBounds(250,330,200,25);
    alternatifEfekSampingStroke3.setBounds(250,360,200,25);
    alternatifEfekSampingStroke4.setBounds(250,390,200,25);
    alternatifEfekSampingStroke5.setBounds(250,420,200,25);
    jawab[5][1].setBounds(450,300,50,25);
    jawab[6][1].setBounds(450,330,50,25);
    jawab[7][1].setBounds(450,360,50,25);
    jawab[8][1].setBounds(450,390,50,25);
    jawab[9][1].setBounds(450,420,50,25);
    alternatifKualitasStroke1.setBounds(500,300,200,25);
    alternatifKualitasStroke2.setBounds(500,330,200,25);
    alternatifKualitasStroke3.setBounds(500,360,200,25);
    alternatifKualitasStroke4.setBounds(500,390,200,25);
    alternatifKualitasStroke5.setBounds(500,420,200,25);
    jawab[10][1].setBounds(700,300,50,25);
    jawab[11][1].setBounds(700,330,50,25);
    jawab[12][1].setBounds(700,360,50,25);
    jawab[13][1].setBounds(700,390,50,25);
    jawab[14][1].setBounds(700,420,50,25);
    alternatifKetersediaanStroke1.setBounds(750,300,200,25);
    alternatifKetersediaanStroke2.setBounds(750,330,200,25);
    alternatifKetersediaanStroke3.setBounds(750,360,200,25);
    alternatifKetersediaanStroke4.setBounds(750,390,200,25);
    alternatifKetersediaanStroke5.setBounds(750,420,200,25);
    jawab[15][1].setBounds(950,300,50,25);
    jawab[16][1].setBounds(950,330,50,25);
    jawab[17][1].setBounds(950,360,50,25);
    jawab[18][1].setBounds(950,390,50,25);
    jawab[19][1].setBounds(950,420,50,25);
    kembali.setBounds(0, 460, 200, 25);
    isi.add(kembali);
    kembali.addActionListener(new java.awt.event.ActionListener() {        
    @Override
    public void actionPerformed(java.awt.event.ActionEvent evt) { 
    ProgramTesisBaru tesis = new ProgramTesisBaru(); 
    tesis.setTitle("Program Pemilihan Obat dengan Cara Analytic Hierarchycal Process");
    tesis.setSize(1024,768);
    tesis.setVisible(true);
    tesis.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tesis.setLocationRelativeTo(null);
    }
    });
    isi.add(stroke1);
    isi.add(alternatifHargaStroke1);
    isi.add(alternatifHargaStroke2);
    isi.add(alternatifHargaStroke3);
    isi.add(alternatifHargaStroke4);
    isi.add(alternatifHargaStroke5);
    isi.add(alternatifEfekSampingStroke1);
    isi.add(alternatifEfekSampingStroke2);
    isi.add(alternatifEfekSampingStroke3);
    isi.add(alternatifEfekSampingStroke4);
    isi.add(alternatifEfekSampingStroke5);
    isi.add(alternatifKualitasStroke1);
    isi.add(alternatifKualitasStroke2);
    isi.add(alternatifKualitasStroke3);
    isi.add(alternatifKualitasStroke4);
    isi.add(alternatifKualitasStroke5);
    isi.add(alternatifKetersediaanStroke1);
    isi.add(alternatifKetersediaanStroke2);
    isi.add(alternatifKetersediaanStroke3);
    isi.add(alternatifKetersediaanStroke4);
    isi.add(alternatifKetersediaanStroke5);
    for (int s = 0; s < 20; s++)
    {
    isi.add(jawab[s][1]);
    }
    }
    }
    How to solve the problem? I got the nullPointerException

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: What is wrong with my code?

    Consider
    • Editing your post above and posting *well-formatted* code. Your current post is all left-justified and long, making it next to impossible to read.
    • Adding an obvious comment (such as // ********* NPE here ********) on the line of code that throws the NPE.
    • Telling us just what this program is supposed to be doing.

  3. #3
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: What is wrong with my code?

    Quote Originally Posted by Fubarable View Post
    Consider
    • Editing your post above and posting *well-formatted* code. Your current post is all left-justified and long, making it next to impossible to read.
    • Adding an obvious comment (such as // ********* NPE here ********) on the line of code that throws the NPE.
    • Telling us just what this program is supposed to be doing.
    Well, here are error messages that I get from the Netbeans:

    Exception in thread "main" java.lang.NullPointerException
    at programtesisbaru.ProgramTesisBaru.<init>(ProgramTe sisBaru.java:66)
    at programtesisbaru.ProgramTesisBaru.main(ProgramTesi sBaru.java:536)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 minute 9 seconds)

    I want to create codes that can be used to choose medicine with AHP methods, can you help me to fix these codes?

  4. #4
    Prime624 is offline Member
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    96
    Rep Power
    0

    Default Re: What is wrong with my code?

    I'm a noob too, but I'm pretty sure that java.lang.NullPointerException means that you are trying to reference an object that has not been created.

    When you use arrays for objects, you need to make a new array as well as make each object individually.

    EDIT: Yes, you created the "kriteria" array, but not each individual "kriteria" object. This is best done with a for-loop.
    Last edited by Prime624; 02-10-2013 at 07:45 PM.
    Fubarable and SurfMan like this.

  5. #5
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: What is wrong with my code?

    I created those arrays but they failed, any other good advices? Can any folks give me any examples?
    Last edited by Tawi; 02-12-2013 at 04:33 PM.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: What is wrong with my code?

    Many of us won't bother looking at code that is unformatted like that.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    927
    Rep Power
    2

    Default Re: What is wrong with my code?

    You created the ARRAY, but not the items IN the array.
    Java Code:
    String[] s = new String[5]; //s contains a reference to a String array
    s[0].toString(); //NullPointerException here, since the 0th item does not exist
    s[0] = "foobar";
    s[0].toString(); //No NullPointerException here, 0th item does exist

  8. #8
    Tawi is offline Senior Member
    Join Date
    Feb 2013
    Posts
    118
    Rep Power
    0

    Default Re: What is wrong with my code?

    So, in my case, what should I do? What should I add?

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: What is wrong with my code?

    Quote Originally Posted by Tawi View Post
    So, in my case, what should I do? What should I add?
    Appropriate spaces and carriage returns. Refer to Code Conventions for the Java Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. What's wrong with my code?
    By Isong in forum AWT / Swing
    Replies: 1
    Last Post: 11-16-2010, 06:00 PM
  2. what is wrong with my code???
    By EBBOOO in forum New To Java
    Replies: 30
    Last Post: 07-27-2010, 09:59 PM
  3. What is wrong with my code?!
    By new2java2009 in forum New To Java
    Replies: 2
    Last Post: 04-17-2010, 08:01 PM
  4. What's wrong with this code?
    By Wizard wusa in forum New To Java
    Replies: 14
    Last Post: 01-22-2008, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •