Results 1 to 5 of 5
  1. #1
    skuskusas is offline Member
    Join Date
    Aug 2012
    Posts
    5
    Rep Power
    0

    Question need some help in Swing

    // hello here i import from to db to JPalnel everithing its ok thats work now me need to delete selected item from db. and add new item to db please help
    import javax.swing.*;

    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;

    public class nn extends JFrame {
    private DefaultListModel model;
    private JButton buttons[];
    private JList dbList;



    private JPanel p1,p2;
    private String bLabel[] = {"parodyti","Ikelti","Istrinti"};

    Connection con;
    Statement st;
    ResultSet rs;
    String db;


    public nn() {

    super("Prekes");

    setSize(500,600);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    model = new DefaultListModel();
    buttons = new JButton[3];
    dbList = new JList(model);

    //Setting up JList property
    dbList.setVisibleRowCount(50);
    dbList.setFixedCellHeight(50);
    dbList.setFixedCellWidth(250);
    dbList.setSelectionMode(ListSelectionModel.SINGLE_ SELECTION);


    p1 = new JPanel();
    p1.setBorder(BorderFactory.createTitledBorder("NR: " +" "+"Week"+" "+"Quantity" ));
    p1.add(new JScrollPane(dbList));



    p2 = new JPanel();
    p2.setLayout(new GridLayout(3,1));
    p2.setBorder(BorderFactory.createTitledBorder("Dis play: "));


    for(int count=0; count<buttons.length; count++) {
    buttons[count] = new JButton(bLabel[count]);
    p2.add(buttons[count]);
    }


    Container pane = getContentPane();
    setContentPane(pane);

    //Set
    GridLayout grid = new GridLayout(1,2);
    pane.setLayout(grid);

    //Creat
    try {
    Class.forName("org.apache.derby.jdbc.ClientDriver" );
    db = "jdbc:derby://localhost:1527/mydatabase";
    con = DriverManager.getConnection(db,"app","app");
    st = con.createStatement();

    } catch (Exception e) {
    JOptionPane.showMessageDialog(null,"Failed to Connect to Database","Error Connection", JOptionPane.WARNING_MESSAGE);
    System.exit(0);
    }


    buttons[0].addActionListener(
    new ActionListener() {


    public void actionPerformed(ActionEvent event) {
    try {
    model.clear();
    rs=st.executeQuery("select * from item");
    while (rs.next()) {
    model.addElement(rs.getString("ItemNO")+" "+rs.getString("WeekNO")+" "+rs.getString("Quantity"));


    }

    } catch (Exception e) {
    System.out.println("nepavyko parodyti duomenu(0)");
    }
    }
    }
    );


    buttons[1].addActionListener(
    new ActionListener() {


    public void actionPerformed(ActionEvent event) {
    try {

    String fileName = ("C://java/SPI00.xls");

    Main app = new Main();
    app.readDataToExcelFile(fileName);


    } catch (Exception e) {
    System.out.println("Nepavyko ikelti duomenu (1)");
    }
    }
    }
    );
    buttons[2].addActionListener(
    new ActionListener() {

    public void actionPerformed(ActionEvent event) {
    try {

    rs=st.executeQuery("delete * from item");


    } catch (Exception e) {
    System.out.println("nepavyko parodyti duomenu(0)");
    }
    }
    }
    );



    pane.add(p1);
    pane.add(p2);




    setVisible(true);
    setResizable(false);
    }


    public static void main (String[] args) {
    nn rdjl = new nn();
    }
    }

  2. #2
    ankiit is offline Member
    Join Date
    Dec 2011
    Location
    India
    Posts
    74
    Rep Power
    0

    Default Re: need some help in Swing

    could you please post the code in correct format(proper indentation). Are you using internal classes?

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

    Default Re: need some help in Swing

    Quote Originally Posted by skuskusas View Post
    need some help in Swing
    Moved from New to Java.

    Please go through the following:
    Forum Rules - -particularly the third paragraph
    Guide For New Members
    BB Code List - Java Programming Forum

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

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: need some help in Swing

    If you don't understand my response, don't ignore it, ask a question.

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

    Default Re: need some help in Swing

    Quote Originally Posted by Norm View Post
    And marked as SOLVED here: [SOLVED] Deleting items after import from JPanel - Java Help - CODECALL

    db

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

Similar Threads

  1. First day of Swing
    By Grish in forum New To Java
    Replies: 10
    Last Post: 06-02-2011, 01:02 PM
  2. About Swing
    By satimis in forum New To Java
    Replies: 2
    Last Post: 05-01-2010, 05:37 PM
  3. swing
    By mnatalka in forum New To Java
    Replies: 5
    Last Post: 12-03-2008, 07:26 AM
  4. AWT or Swing
    By bugger in forum AWT / Swing
    Replies: 4
    Last Post: 11-22-2007, 09:44 AM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 07:02 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
  •