السلام عليكم
اخواني حبيت اني ازي من جمال مظهر الفريم واحط خلفيه له بس ماعرفت الكود المناسب
هل يعني في كود يخلي الصوره شفافه ام اني اخليها شفافه بالفوتوشوب واضعها
اجوا منك افادتي
وشكرا
السلام عليكم
اخواني حبيت اني ازي من جمال مظهر الفريم واحط خلفيه له بس ماعرفت الكود المناسب
هل يعني في كود يخلي الصوره شفافه ام اني اخليها شفافه بالفوتوشوب واضعها
اجوا منك افادتي
وشكرا
لوضع صورة كخلفية للـ Frame أضيفي الشيفرة التالية إلى صف الـ Frame :
public void paint(Graphics g) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("image.jpg")); //"image.jpg" is the name of the image you want to add
}
catch (IOException ex) {
}
g.drawImage(img, 0, 0, this);
}و لجعل الصوره شفافه
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Image image = getToolkit().getImage("face.jpg");
AlphaComposite comp =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
0.5f);
g2d.setComposite(comp);
g2d.drawImage(image, null, this);
}و لتغيير درجه الشفافيه يحتاج فقط الى تغيير القيمه 0.5f
السلام عليكم شكرا اخي MMSs
بالنسبه للكود الي جبته طلع لي خطأ في الفورم
import javax.swing.border.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.io.*;
public class Customer extends JFrame implements ActionListener{
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
JLabel lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8,lb9,lb10;
JButton a,d,u,s,n,p,ca,e;
JPanel
p1,p11,p12,p2,pc,pc1,pc2,pc3,pc4,pn,pn1,pn2,pn3,pn4,pp,p3,p31,p32,p24,
p4,p41,p42;
Container c;
Font font;
Connection con=null;
static Customer ob;
Statement stat=null;
ResultSet rs=null;
int update=0;
int cnt=1;
public Customer(){
c=getContentPane();
c.setLayout(new BorderLayout());
p1=new JPanel();
p11=new JPanel();
lb1=new JLabel("");
p11.add(lb1);
p12=new JPanel();
font=new Font("Dialog",1,30);
lb2=new JLabel("Customer Information",JLabel.CENTER);
lb2.setFont(font);
p12.add(lb2);
p1.add(p11);p1.add(p12);
c.add(p1,BorderLayout.NORTH);
TitledBorder title;
Border
blackline=BorderFactory.createLineBorder(Color.black);
title=BorderFactory.createTitledBorder(blackline,"");
p2=new JPanel(new GridLayout(2,1));
pc=new JPanel(new GridLayout(4,1));
pc1=new JPanel();
lb3 =new JLabel("Customer Code : ");
tf1=new JTextField(15);
pc1.add(lb3);pc1.add(tf1);
pc.add(pc1);
pc2=new JPanel();
lb4 =new JLabel("Customer Name : ");
tf2=new JTextField(15);
pc2.add(lb4);pc2.add(tf2);
pc.add(pc2);
pc3=new JPanel();
lb5 =new JLabel("Customer Phone : ");
tf3=new JTextField(15);
pc3.add(lb5);pc3.add(tf3);
pc.add(pc3);
pc4=new JPanel();
lb6 =new JLabel("Customer Address : ");
tf4=new JTextField(15);
pc4.add(lb6);pc4.add(tf4);
pc.add(pc4);
pn=new JPanel(new GridLayout(6,1));
pn1=new JPanel(new GridLayout(1,2,2,2));
s=new JButton("Save");
ca=new JButton("Cancel");
pn1.add(s);pn1.add(ca);
pn.add(pn1);
pn2=new JPanel(new GridLayout(1,2,2,2));
a=new JButton("Insert Row");
u=new JButton("Update Row");
pn2.add(a);pn2.add(u);
pn.add(pn2);
pn3=new JPanel(new GridLayout(1,2,2,2));
d=new JButton(" Delete Row");
e=new JButton("Close Form");
e.addActionListener(new ActionListener(){
public void
actionPerformed(ActionEvent ae){
setVisible(false);
}
});
pn3.add(d);pn3.add(e);
pn.add(pn3);
pn4=new JPanel(new GridLayout(1,2,2,2));
n=new JButton("Next");
p=new JButton("Previous");
p.addActionListener(this);
pn4.add(n);pn4.add(p);
pn.add(pn4);
p2.setBorder(title);
p2.add(pc);p2.add(pn);
c.add(p2);
p3=new JPanel(new GridLayout(1,1));
p31=new JPanel();
lb7=new JLabel(" ");
p31.add(lb7);p3.add(p31);
//p32=new JPanel();
//lb8=new JLabel(" ");
//p32.add(lb8);p3.add(p32);
c.add(p3,BorderLayout.WEST);
p4=new JPanel(new GridLayout(1,1));
p41=new JPanel();
lb9=new JLabel(" ");
p41.add(lb9);p4.add(p41);
//p42=new JPanel();
//lb10=new JLabel(" ");
//p42.add(lb10);p4.add(p42);
c.add(p4,BorderLayout.EAST);
lb8=new JLabel(" ");
c.add(lb8,BorderLayout.SOUTH);
a.addActionListener(this);
n.addActionListener(this);
p.addActionListener(this);
ca.addActionListener(this);
s.addActionListener(this);
u.addActionListener(this);
d.addActionListener(this);
e.addActionListener(this);
ca.setEnabled(false);
s.setEnabled(false);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:san");
stat=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs=stat.executeQuery("select * from Customer");
rs.next();
displayRow();
lockTF();
}catch(Exception ea){}
}
/*void displayRow()throws Exception{
tf1.setText(rs.getString(1));
tf2.setText(rs.getString(2));
tf3.setText(rs.getString(3));
tf4.setText(rs.getString(4));
System.out.println("Now in: "+rs.getRow());
}*/
void displayRow()throws Exception{
tf1.setText(rs.getString(1));
tf2.setText(rs.getString(2));
tf3.setText(rs.getString(3));
tf4.setText(rs.getString(4));
System.out.println("Now in: "+rs.getRow());
}
void lockTF(){
tf1.setEditable(false);
tf2.setEditable(false);
tf3.setEditable(false);
tf4.setEditable(false);
}
void fillRow()throws Exception{
rs.updateString(1,tf1.getText());
rs.updateString(2,tf2.getText());
rs.updateString(3,tf3.getText());
rs.updateString(4,tf4.getText());
}
void unLockTF(){
tf1.setEditable(true);
tf2.setEditable(true);
tf3.setEditable(true);
tf4.setEditable(true);
System.out.println("Text Field UnLocked
Successfully");
}
void disableButton(){
a.setEnabled(false);
u.setEnabled(false);
d.setEnabled(false);
n.setEnabled(false);
p.setEnabled(false);
e.setEnabled(false);
}
void enableButton(){
a.setEnabled(true);
u.setEnabled(true);
d.setEnabled(true);
n.setEnabled(true);
p.setEnabled(true);
e.setEnabled(true);
}/*
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Image image = getToolkit().getImage("ss.gif");
AlphaComposite comp =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
0.5f);
g2d.setComposite(comp);
g2d.drawImage(image, null, this);
}
*/
public void paint(Graphics g) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("ss.gif")); //"image.jpg" is the name
}
catch (IOException ex) {
}
g.drawImage(img, 0, 0, this);
}
public void actionPerformed(ActionEvent ae){
try{
/*if(ae.getSource()==e){
Framey ob=new Framey();
ob.setVisible(true);
}*/
if(ae.getActionCommand()=="Next")
if(rs.isLast()!=true){
rs.next();
cnt++;
displayRow();
}
if(ae.getSource()==p){
if(rs.isFirst()!=true){
rs.previous();
cnt--;
displayRow();
}
}
if(ae.getActionCommand()=="Insert Row"){
unLockTF();
rs.moveToInsertRow();
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
disableButton();
s.setEnabled(true);
ca.setEnabled(true);
}
if(ae.getActionCommand()=="Update Row"){
unLockTF();
update=1;
disableButton();
s.setEnabled(true);
ca.setEnabled(true);
System.out.println("Now You Can Update
Record");
}
if((ae.getActionCommand()=="Save")&&(update==0)){
System.out.println("One Record Added
Successfully");
fillRow();
s.setEnabled(false);
ca.setEnabled(false);
enableButton();
rs.insertRow();
rs.moveToCurrentRow();
lockTF();
displayRow();
}
if((ae.getActionCommand()=="Save")&&
(update==1)){
int upd=rs.getRow();
rs.absolute(upd);
fillRow();
s.setEnabled(false);
ca.setEnabled(false);
enableButton();
rs.updateRow();
lockTF();
System.out.println("One Record Updated
Successfully");
}
if(ae.getActionCommand()==" Delete Row"){
rs.deleteRow();
rs.refreshRow();
if(!rs.isFirst())
rs.previous();
System.out.println("One Record Deleted
ccessfully");
}
if(ae.getActionCommand()=="Cancel"){
ca.setEnabled(false);
s.setEnabled(false);
enableButton();
}
if (update==0)rs.moveToCurrentRow();
if(update==1){
rs.cancelRowUpdates();
rs.refreshRow();
}
}catch(Exception e){}
//lockTF();
//displayRow();
}
public static void main(String s[]){
ob=new Customer();
ob.setTitle("Customer Form");
ob.setSize(400,450);
ob.setLocation(100,100);
ob.setResizable(false);
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
}
}وشكرا لك اخي ashraf83de
بس لاحظت بالفورم ان buttons ما تظهر الا بد ان امرر الماوس عليها وان كل الفورم شكله تغير
ليش :s
أسف نسيت أن أمر استدعاء الصفوف التالية من حزمها :
import java.awt.image.BufferedImage; import java.imageio.ImageIO;
أتمنى أن يكون هذا هو السبب وقد حلت المشكلة.
عذراً على الخطأ مرة أخرى! المفروض javax وليس java ، كما يلي :
import javax.imageio.ImageIO;
عذراً مرة أخرى! أتمنى أن تكون المشكلة قد حلت الآن.
السلام عليكم
شكرا لك اخي اظن ان المشكله حلت ولكني لدي سؤال اخر لماذا لا يظهر شكل الفريم (buttons ,textfield) الا بعد ان امرر الماوس على الفريم
استخدمي:
this.valifdate()
بعد اجراء عمليات الرسم او الاصافة على الفريم.
اسف سوف اقطعك من كتابة الكود، ادخل هنا لدقيقتين فقط
او غيري الميثود main لتصبح بهذا الشكل:
public static void main(String s[]){
ob=new Customer();
ob.setTitle("Customer Form");
ob.setSize(400,450);
ob.setLocation(100,100);
ob.setResizable(false);
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
for(Component comp : ob.getComponents())
if(comp instanceof Container)
comp.repaint();
}تم تعديل هذه المشاركة بواسطة مبتدئ جدا في 14 سبتمبر 2005 في 11:30
اسف سوف اقطعك من كتابة الكود، ادخل هنا لدقيقتين فقط
اشكرك اخي مبتدئ جدا ولكنني اظن ان المشكله بعدها ما انحلت الصوره.... صح الصوره تظهر بس buttons لا يعني لازم احرك الماوس
ممكن تضع الشفرة المصدرية هنا بعد كل التعديلات التي أضفتها؟
صفحاتي: صفحة حسام الملحم www.hussam.ws مدونة
آخر المشاريع: مشروع لغة برمجة عربية شيئية التوجه
ألعاب على الجوال : 1-(لعبة O X على الجوال ) 2-(لعبة الرقم السري على الجوال ) 3-(لعبة آخر حبة على الجوال )
ألعاب على الحاسب: لعبة الوزراء الثمان ، لعبة شطرنج ، لعبة التركيب Tetris
مواضيعي:
الفرق الجذري بين الجافا و C# شرح التعامل مع WTK لبرمجة الجوالات
مشاركاتي:
برنامج (كاتب) للكاتب فهد OMLX، برنامج (المحول) للكاتب فهد OMLX، برنامج (Unit Storm) للكاتب بشير C&Dell، أيهما أكبر الأعداد الصحيحة أم الطبيعية للكاتب Romanof، سؤال رياضي بحت للكاتب VB6-Rocket، التحدي الكبير للكاتب ANSI،
ال Buttons تظهر عندي بدون اية مشاكل.
-------------------------------------------
اسف سوف اقطعك من كتابة الكود، ادخل هنا لدقيقتين فقط
import javax.swing.border.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.io.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Customer extends JFrame implements ActionListener{
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
JLabel lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8,lb9,lb10;
JButton a,d,u,s,n,p,ca,e;
JPanel
p1,p11,p12,p2,pc,pc1,pc2,pc3,pc4,pn,pn1,pn2,pn3,pn4,pp,p3,p31,p32,p24,
p4,p41,p42;
Container c;
Font font;
Connection con=null;
static Customer ob;
Statement stat=null;
ResultSet rs=null;
int update=0;
int cnt=1;
public Customer(){
c=getContentPane();
c.setLayout(new BorderLayout());
p1=new JPanel();
p11=new JPanel();
lb1=new JLabel("");
p11.add(lb1);
p12=new JPanel();
font=new Font("Dialog",1,30);
lb2=new JLabel("Customer Information",JLabel.CENTER);
lb2.setFont(font);
p12.add(lb2);
p1.add(p11);p1.add(p12);
c.add(p1,BorderLayout.NORTH);
TitledBorder title;
Border
blackline=BorderFactory.createLineBorder(Color.black);
title=BorderFactory.createTitledBorder(blackline,"");
p2=new JPanel(new GridLayout(2,1));
pc=new JPanel(new GridLayout(4,1));
pc1=new JPanel();
lb3 =new JLabel("Customer Code : ");
tf1=new JTextField(15);
pc1.add(lb3);pc1.add(tf1);
pc.add(pc1);
pc2=new JPanel();
lb4 =new JLabel("Customer Name : ");
tf2=new JTextField(15);
pc2.add(lb4);pc2.add(tf2);
pc.add(pc2);
pc3=new JPanel();
lb5 =new JLabel("Customer Phone : ");
tf3=new JTextField(15);
pc3.add(lb5);pc3.add(tf3);
pc.add(pc3);
pc4=new JPanel();
lb6 =new JLabel("Customer Address : ");
tf4=new JTextField(15);
pc4.add(lb6);pc4.add(tf4);
pc.add(pc4);
pn=new JPanel(new GridLayout(6,1));
pn1=new JPanel(new GridLayout(1,2,2,2));
s=new JButton("Save");
ca=new JButton("Cancel");
pn1.add(s);pn1.add(ca);
pn.add(pn1);
pn2=new JPanel(new GridLayout(1,2,2,2));
a=new JButton("Insert Row");
u=new JButton("Update Row");
pn2.add(a);pn2.add(u);
pn.add(pn2);
pn3=new JPanel(new GridLayout(1,2,2,2));
d=new JButton(" Delete Row");
e=new JButton("Close Form");
e.addActionListener(new ActionListener(){
public void
actionPerformed(ActionEvent ae){
setVisible(false);
}
});
pn3.add(d);pn3.add(e);
pn.add(pn3);
pn4=new JPanel(new GridLayout(1,2,2,2));
n=new JButton("Next");
p=new JButton("Previous");
p.addActionListener(this);
pn4.add(n);pn4.add(p);
pn.add(pn4);
p2.setBorder(title);
p2.add(pc);p2.add(pn);
c.add(p2);
p3=new JPanel(new GridLayout(1,1));
p31=new JPanel();
lb7=new JLabel(" ");
p31.add(lb7);p3.add(p31);
//p32=new JPanel();
//lb8=new JLabel(" ");
//p32.add(lb8);p3.add(p32);
c.add(p3,BorderLayout.WEST);
p4=new JPanel(new GridLayout(1,1));
p41=new JPanel();
lb9=new JLabel(" ");
p41.add(lb9);p4.add(p41);
//p42=new JPanel();
//lb10=new JLabel(" ");
//p42.add(lb10);p4.add(p42);
c.add(p4,BorderLayout.EAST);
lb8=new JLabel(" ");
c.add(lb8,BorderLayout.SOUTH);
a.addActionListener(this);
n.addActionListener(this);
p.addActionListener(this);
ca.addActionListener(this);
s.addActionListener(this);
u.addActionListener(this);
d.addActionListener(this);
e.addActionListener(this);
ca.setEnabled(false);
s.setEnabled(false);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:san");
stat=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs=stat.executeQuery("select * from Customer");
rs.next();
displayRow();
lockTF();
}catch(Exception ea){}
}
/*void displayRow()throws Exception{
tf1.setText(rs.getString(1));
tf2.setText(rs.getString(2));
tf3.setText(rs.getString(3));
tf4.setText(rs.getString(4));
System.out.println("Now in: "+rs.getRow());
}*/
void displayRow()throws Exception{
tf1.setText(rs.getString(1));
tf2.setText(rs.getString(2));
tf3.setText(rs.getString(3));
tf4.setText(rs.getString(4));
System.out.println("Now in: "+rs.getRow());
}
void lockTF(){
tf1.setEditable(false);
tf2.setEditable(false);
tf3.setEditable(false);
tf4.setEditable(false);
}
void fillRow()throws Exception{
rs.updateString(1,tf1.getText());
rs.updateString(2,tf2.getText());
rs.updateString(3,tf3.getText());
rs.updateString(4,tf4.getText());
}
void unLockTF(){
tf1.setEditable(true);
tf2.setEditable(true);
tf3.setEditable(true);
tf4.setEditable(true);
System.out.println("Text Field UnLocked Successfully");
}
void disableButton(){
a.setEnabled(false);
u.setEnabled(false);
d.setEnabled(false);
n.setEnabled(false);
p.setEnabled(false);
e.setEnabled(false);
}
void enableButton(){
a.setEnabled(true);
u.setEnabled(true);
d.setEnabled(true);
n.setEnabled(true);
p.setEnabled(true);
e.setEnabled(true);
}/*
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Image image = getToolkit().getImage("ss.gif");
AlphaComposite comp =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
0.5f);
g2d.setComposite(comp);
g2d.drawImage(image, null, this);
}
*/
public void paint(Graphics g) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("ss.gif")); //"image.jpg" is the name
}
catch (IOException ex) {
}
g.drawImage(img, 0, 0, this);
}
public void actionPerformed(ActionEvent ae){
try{
/*if(ae.getSource()==e){
Framey ob=new Framey();
ob.setVisible(true);
}*/
if(ae.getActionCommand()=="Next")
if(rs.isLast()!=true){
rs.next();
cnt++;
displayRow();
}
if(ae.getSource()==p){
if(rs.isFirst()!=true){
rs.previous();
cnt--;
displayRow();
}
}
if(ae.getActionCommand()=="Insert Row"){
unLockTF();
rs.moveToInsertRow();
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
disableButton();
s.setEnabled(true);
ca.setEnabled(true);
}
if(ae.getActionCommand()=="Update Row"){
unLockTF();
update=1;
disableButton();
s.setEnabled(true);
ca.setEnabled(true);
System.out.println("Now You Can Update Record");
}
if((ae.getActionCommand()=="Save")&&(update==0)){
System.out.println("One Record Added Successfully");
fillRow();
s.setEnabled(false);
ca.setEnabled(false);
enableButton();
rs.insertRow();
rs.moveToCurrentRow();
lockTF();
displayRow();
}
if((ae.getActionCommand()=="Save")&&
(update==1)){
int upd=rs.getRow();
rs.absolute(upd);
fillRow();
s.setEnabled(false);
ca.setEnabled(false);
enableButton();
rs.updateRow();
lockTF();
System.out.println("One Record Updated Successfully");
}
if(ae.getActionCommand()==" Delete Row"){
rs.deleteRow();
rs.refreshRow();
if(!rs.isFirst())
rs.previous();
System.out.println("One Record Deleted ccessfully");
}
if(ae.getActionCommand()=="Cancel"){
ca.setEnabled(false);
s.setEnabled(false);
enableButton();
}
if (update==0)rs.moveToCurrentRow();
if(update==1){
rs.cancelRowUpdates();
rs.refreshRow();
}
}catch(Exception e){}
//lockTF();
//displayRow();
}
public static void main(String s[]){
ob=new Customer();
ob.setTitle("Customer Form");
ob.setSize(400,450);
ob.setLocation(100,100);
ob.setResizable(false);
ob.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ob.setVisible(true);
for(Component comp : ob.getComponents())
if(comp instanceof Container)
comp.repaint();
}
}هذه ملاحظات على الشفرة:
1- كان يجب أن تقسم المشروع إلى Customer ، CustomerDataBase, CustomerGUI
وليس إلى Customer يحوي كل شيء.
2- الصورة حملها مرة واحدة وليس كلما نريد إعادة رسم الواجهة.
3- لماذا كل هذه المكونات pc, pc1 pc4, وغيرها وغيرها.. لماذا لا تستعمل مصفوفة بدل هذه العشوائية؟ أو استخدم التوجه الكائني أكثر من هذا.
4- لماذا لا تطبع الأخطاء؟؟!!! أكبر خطأ في برنامجك هو هذا:
try{
//code
}
catch(Exception ex){}هكذا لن تعرف الأخطاء أبدا!!
دائما وأبدا اطبع الأخطاء :
try{
//code
}
catch(Exception ex){
ex.printStackTrace();
}---
ليس عندي وقت لشرح المزيد الآن في كيفية تصميم برنامج مثل هذا، لكن لحل المشكلة سريعا:
import javax.swing.border.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.sql.*;
import java.io.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
class GUIDecorator{
public static JButton getButton(String message){
JButton b=new JButton (message);
b.setOpaque(false);
return b;
}
public static JPanel createPanel(){
JPanel panel=new JPanel();
panel.setOpaque(false);
return panel;
}
public static JPanel createPanel(LayoutManager l){
JPanel panel=new JPanel(l);
panel.setOpaque(false);
return panel;
}
}
class Customer extends JPanel implements ActionListener{
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
JLabel lb1,lb2,lb3,lb4,lb5,lb6,lb7,lb8,lb9,lb10;
JButton a,d,u,s,n,p,ca,e;
JPanel
p1,p11,p12,p2,pc,pc1,pc2,pc3,pc4,pn,pn1,pn2,pn3,pn4,pp,p3,p31,p32,p24,
p4,p41,p42;
Font font;
Connection con=null;
static Customer ob;
Statement stat=null;
ResultSet rs=null;
int update=0;
int cnt=1;
BufferedImage img;
public Customer(){
prepareImages();
setLayout(new BorderLayout());
this.setOpaque(false);
p1=GUIDecorator.createPanel();
p11=GUIDecorator.createPanel();
lb1=new JLabel("");
p11.add(lb1);
p12=GUIDecorator.createPanel();
font=new Font("Dialog",1,30);
lb2=new JLabel("Customer Information",JLabel.CENTER);
lb2.setFont(font);
p12.add(lb2);
p1.add(p11);p1.add(p12);
add(p1,BorderLayout.NORTH);
TitledBorder title;
Border
blackline=BorderFactory.createLineBorder(Color.black);
title=BorderFactory.createTitledBorder(blackline,"");
p2=GUIDecorator.createPanel();
p2.setLayout(new GridLayout(2,1));
pc=GUIDecorator.createPanel();
pc.setLayout(new GridLayout(4,1));
pc1=GUIDecorator.createPanel();
lb3 =new JLabel("Customer Code : ");
boolean FLAG=false;
tf1=new JTextField(15);
pc1.add(lb3);pc1.add(tf1);
pc.add(pc1);
pc2=GUIDecorator.createPanel();
lb4 =new JLabel("Customer Name : ");
tf2=new JTextField(15);
pc2.add(lb4);pc2.add(tf2);
pc.add(pc2);
pc3=GUIDecorator.createPanel();
lb5 =new JLabel("Customer Phone : ");
tf3=new JTextField(15);
pc3.add(lb5);pc3.add(tf3);
pc.add(pc3);
pc4=GUIDecorator.createPanel();
lb6 =new JLabel("Customer Address : ");
tf4=new JTextField(15);
pc4.add(lb6);pc4.add(tf4);
pc.add(pc4);
pn=GUIDecorator.createPanel();
pn.setLayout(new GridLayout(6,1));
pn1=GUIDecorator.createPanel();
pn1.setLayout(new GridLayout(1,2,2,2));
s=new JButton("Save");
ca=new JButton("Cancel");
pn1.add(s);pn1.add(ca);
pn.add(pn1);
pn2=GUIDecorator.createPanel();
pn2.setLayout(new GridLayout(1,2,2,2));
a=new JButton("Insert Row");
u=new JButton("Update Row");
pn2.add(a);pn2.add(u);
pn.add(pn2);
pn3=GUIDecorator.createPanel();
pn3.setLayout(new GridLayout(1,2,2,2));
d=new JButton(" Delete Row");
e=new JButton("Close Form");
e.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
setVisible(false);
}});
pn3.add(d);pn3.add(e);
pn.add(pn3);
pn4=GUIDecorator.createPanel();
pn4.setLayout(new GridLayout(1,2,2,2));
n=new JButton("Next");
p=new JButton("Previous");
p.addActionListener(this);
pn4.add(n);pn4.add(p);
pn.add(pn4);
p2.setBorder(title);
p2.add(pc);p2.add(pn);
add(p2);
p3=GUIDecorator.createPanel();
p3.setLayout(new GridLayout(1,1));
p31=GUIDecorator.createPanel();
lb7=new JLabel(" ");
p31.add(lb7);p3.add(p31);
//p32=new JPanel();
//lb8=new JLabel(" ");
//p32.add(lb8);p3.add(p32);
add(p3,BorderLayout.WEST);
p4=GUIDecorator.createPanel();
p4.setLayout(new GridLayout(1,1));
p41=GUIDecorator.createPanel();
lb9=new JLabel(" ");
p41.add(lb9);p4.add(p41);
//p42=new JPanel();
//lb10=new JLabel(" ");
//p42.add(lb10);p4.add(p42);
add(p4,BorderLayout.EAST);
lb8=new JLabel(" ");
add(lb8,BorderLayout.SOUTH);
a.addActionListener(this);
n.addActionListener(this);
p.addActionListener(this);
ca.addActionListener(this);
s.addActionListener(this);
u.addActionListener(this);
d.addActionListener(this);
e.addActionListener(this);
ca.setEnabled(false);
s.setEnabled(false);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:san");
stat=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rs=stat.executeQuery("select * from Customer");
rs.next();
displayRow();
lockTF();
}catch(Exception ea){
//Always print the ERROR
ea.printStackTrace();
}
}
private void prepareImages(){
img = null;
try {
img = ImageIO.read(new File("Filfillah.JPG")); //"image.jpg" is the name
}
catch (IOException ex) {
//Always print the Error
ex.printStackTrace();
}
}
/*void displayRow()throws Exception{
tf1.setText(rs.getString(1));
tf2.setText(rs.getString(2));
tf3.setText(rs.getString(3));
tf4.setText(rs.getString(4));
System.out.println("Now in: "+rs.getRow());
}*/
void displayRow()throws Exception{
tf1.setText(rs.getString(1));
tf2.setText(rs.getString(2));
tf3.setText(rs.getString(3));
tf4.setText(rs.getString(4));
System.out.println("Now in: "+rs.getRow());
}
void lockTF(){
tf1.setEditable(false);
tf2.setEditable(false);
tf3.setEditable(false);
tf4.setEditable(false);
}
void fillRow()throws Exception{
rs.updateString(1,tf1.getText());
rs.updateString(2,tf2.getText());
rs.updateString(3,tf3.getText());
rs.updateString(4,tf4.getText());
}
void unLockTF(){
tf1.setEditable(true);
tf2.setEditable(true);
tf3.setEditable(true);
tf4.setEditable(true);
System.out.println("Text Field UnLocked Successfully");
}
void disableButton(){
a.setEnabled(false);
u.setEnabled(false);
d.setEnabled(false);
n.setEnabled(false);
p.setEnabled(false);
e.setEnabled(false);
}
void enableButton(){
a.setEnabled(true);
u.setEnabled(true);
d.setEnabled(true);
n.setEnabled(true);
p.setEnabled(true);
e.setEnabled(true);
}/*
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Image image = getToolkit().getImage("ss.gif");
AlphaComposite comp =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
0.5f);
g2d.setComposite(comp);
g2d.drawImage(image, null, this);
}
*/
public void paint(Graphics g) {
BufferedImage img = null;
try {
img = ImageIO.read(new File("Filfillah.JPG")); //"image.jpg" is the name
}
catch (IOException ex) {
//Always print the Error
ex.printStackTrace();
}
g.drawImage(img, 0, 0, this);
super.paint(g);
}
public void actionPerformed(ActionEvent ae){
try{
/*if(ae.getSource()==e){
Framey ob=new Framey();
ob.setVisible(true);
}*/
if(ae.getActionCommand()=="Next")
if(rs.isLast()!=true){
rs.next();
cnt++;
displayRow();
}
if(ae.getSource()==p){
if(rs.isFirst()!=true){
rs.previous();
cnt--;
displayRow();
}
}
if(ae.getActionCommand()=="Insert Row"){
unLockTF();
rs.moveToInsertRow();
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
disableButton();
s.setEnabled(true);
ca.setEnabled(true);
}
if(ae.getActionCommand()=="Update Row"){
unLockTF();
update=1;
disableButton();
s.setEnabled(true);
ca.setEnabled(true);
System.out.println("Now You Can Update Record");
}
if((ae.getActionCommand()=="Save")&&(update==0)){
System.out.println("One Record Added Successfully");
fillRow();
s.setEnabled(false);
ca.setEnabled(false);
enableButton();
rs.insertRow();
rs.moveToCurrentRow();
lockTF();
displayRow();
}
if((ae.getActionCommand()=="Save")&&
(update==1)){
int upd=rs.getRow();
rs.absolute(upd);
fillRow();
s.setEnabled(false);
ca.setEnabled(false);
enableButton();
rs.updateRow();
lockTF();
System.out.println("One Record Updated Successfully");
}
if(ae.getActionCommand()==" Delete Row"){
rs.deleteRow();
rs.refreshRow();
if(!rs.isFirst())
rs.previous();
System.out.println("One Record Deleted ccessfully");
}
if(ae.getActionCommand()=="Cancel"){
ca.setEnabled(false);
s.setEnabled(false);
enableButton();
}
if (update==0)rs.moveToCurrentRow();
if(update==1){
rs.cancelRowUpdates();
rs.refreshRow();
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String s[]){
JFrame frame=new JFrame();
ob=new Customer();
frame.add(ob);
frame.setTitle("Customer Form");
frame.setSize(400,450);
frame.setLocation(100,100);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}أرجو ملاحظة:
1- وظيفة الأمر setOpaque..
2- وظيفة الأمر super.paint()
3-وظيفة الفئة الجديدة GUIDecorator!
أرجو أن تفيدك قليلا!
بالتوفيق!!
صفحاتي: صفحة حسام الملحم www.hussam.ws مدونة
آخر المشاريع: مشروع لغة برمجة عربية شيئية التوجه
ألعاب على الجوال : 1-(لعبة O X على الجوال ) 2-(لعبة الرقم السري على الجوال ) 3-(لعبة آخر حبة على الجوال )
ألعاب على الحاسب: لعبة الوزراء الثمان ، لعبة شطرنج ، لعبة التركيب Tetris
مواضيعي:
الفرق الجذري بين الجافا و C# شرح التعامل مع WTK لبرمجة الجوالات
مشاركاتي:
برنامج (كاتب) للكاتب فهد OMLX، برنامج (المحول) للكاتب فهد OMLX، برنامج (Unit Storm) للكاتب بشير C&Dell، أيهما أكبر الأعداد الصحيحة أم الطبيعية للكاتب Romanof، سؤال رياضي بحت للكاتب VB6-Rocket، التحدي الكبير للكاتب ANSI،
:D جاي بكيير
المشكله في الكود هو عدم ظهور ال button & textField الا بعد تحريك الماوس فوقها
وهذا بسبب ال JPanel ( على حسب التجربه )
فلو استبدلت JPanel بـ Panel في الكود السابق لأنتهت المشكلة .
المرفق مثال بسيط لعمل صوره كخلفيه JFrame
( لتوضيح الفكره فقط )
السؤال المهم ::
لو استبدلنا Panel بـ JPanel في المثال المرفق لماذا يختفي الـ button & textField ؟
.jpg)
حل ذلك في شفرتي... حاول معرفة فائدة بعض الأوامر المهمة!
setOpaque وظيفته تحديد هل القطعة شفافة أم غير شفافة!
صفحاتي: صفحة حسام الملحم www.hussam.ws مدونة
آخر المشاريع: مشروع لغة برمجة عربية شيئية التوجه
ألعاب على الجوال : 1-(لعبة O X على الجوال ) 2-(لعبة الرقم السري على الجوال ) 3-(لعبة آخر حبة على الجوال )
ألعاب على الحاسب: لعبة الوزراء الثمان ، لعبة شطرنج ، لعبة التركيب Tetris
مواضيعي:
الفرق الجذري بين الجافا و C# شرح التعامل مع WTK لبرمجة الجوالات
مشاركاتي:
برنامج (كاتب) للكاتب فهد OMLX، برنامج (المحول) للكاتب فهد OMLX، برنامج (Unit Storm) للكاتب بشير C&Dell، أيهما أكبر الأعداد الصحيحة أم الطبيعية للكاتب Romanof، سؤال رياضي بحت للكاتب VB6-Rocket، التحدي الكبير للكاتب ANSI،
: )
ليتي أعرف
هذا الموضوع مغلق.