الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال بال JDialog و عرض البيانات

مغلق
بدأه صلاح الثبيتي في 19 يونيو 2003 · 8 رد · 766 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم :)

عندي مشكله بسيطه لكن ما عرفت لها حل و هي عندي JDialog و فيها JTable اعرض فيها بيانات من قاعدة بيانات .. المشكله الوحيده هي اذا ضغطت على X (بطرف الـ JDialog). و دخلت مره ثانيه على الـ JDialog ..

اشوف ان الـ JDialog صار فيه 2 من الـ JTable و اذا ضغطت على X مره ثانيه و فتحت الـ JDialog مره ثالثه اكتشف ان عندي 3 من الـ JTable ...

احد عنده فكره ؟؟

الكود:

import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;

public class listBook extends JDialog {
	private Connection connection = null;
	private Statement statement = null;
	private ResultSet resultset = null;

	private Vector data = new Vector();
	private Vector head = new Vector();
	private Vector oneRow;

	private JPanel panel = new JPanel();
	//private JLabel label;
	private JTable table;
	private TableColumn column = null;
	private JScrollPane scrollPane;

    Library l;
    public listBook(Library l) {
        this.l = l;
    }
	public void listBook(Frame frame, String title, boolean model) {
		setTitle(title);
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		}
		catch(Exception e) {}
		try {
			connection = DriverManager.getConnection("jdbc:odbc:Library");
			statement  = connection.createStatement();
			//statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			resultset  = statement.executeQuery("select * from Books");
			while(resultset.next()) {
				oneRow = new Vector();
				oneRow.add(resultset.getString("title"));
				oneRow.add(resultset.getString("authers"));
				oneRow.add(resultset.getString("publisher"));
				oneRow.add(resultset.getString("editionNumber"));
				oneRow.add(resultset.getString("copyRightYear"));
				oneRow.add(resultset.getString("ISBN"));
				data.add(oneRow);
			}
			resultset.close();
			statement.close();
			connection.close();
		}
		catch(SQLException sqle) {
			System.out.println(sqle.toString());
		}
		head.add("Title");
		head.add("Authers");
		head.add("Publisher");
		head.add("Edition");
		head.add("Copyright Year");
		head.add("ISBN");
		table = new JTable(data, head);
		table.setFont(new Font("Tahoma", Font.PLAIN, 11));
		scrollPane = new JScrollPane(table);
		//label = new JLabel("The List of All Books");

		//table.setRowSelectionAllowed(false);
		//table.setColumnSelectionAllowed(false);
		//table.setPreferredScrollableViewportSize(new Dimension(500, 75));
		for(int i = 0; i < 6; i++) {
			column = table.getColumnModel().getColumn(i);
			if(i == 0)
				column.setPreferredWidth(200);
			if(i == 1)
				column.setPreferredWidth(100);
			if(i == 2)
				column.setPreferredWidth(100);
			if(i == 3)
				column.setPreferredWidth(100);
			if(i == 4)
				column.setPreferredWidth(100);
			if(i == 5)
				column.setPreferredWidth(120);
		}
		getContentPane().add(panel);
		panel.setLayout(new FlowLayout(FlowLayout.CENTER));
		//panel.add(label);
		panel.add(scrollPane, BorderLayout.CENTER);
		//panel.add(table);
		setVisible(true);
		pack();
	}
}

الصور بالمرفقات...

jtable.zip

#2

try to dispose the jdialog when it is closed

public listBook(Library l) {
        this.l = l;
 this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
    }
#3

Hi ,

My JBuilder 8 always hang when I try to save.Are you sure that the serial number you gave me is Halal :D

#5

it looks like u using the second constructor not the first.if this is the case then add the highlighted code to the second constructor

#7

you r declaring listbook outside the event handler,so the same dialog get used everytime which increments the number of jtables.try to declare it inside the event handler

#8

another thing ,jdialog is not appropriate ,you could have used JInternalFrame

#9

مشكور على التوضيح،،

انا الحين قاعد اجرب كيفيه عمل مثل هذي النوعيه من البرامج مع قواعد البيانات .. طبعا بالنسخه الثانيه راح احاول عمل افضل شكل للبرنامج بافضل الحلول :P

هذا الموضوع مغلق.

مواضيع مشابهة