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

كيف اربط Button في كلاس Jframe بميثود في كلاس اخر

بدأه abduo_1155 في 5 مايو 2009 · 6 رد · 744 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه ،،

اخواني وخواتي الكرام

عندي هذا الكلاس اخته من موضوع شخص في المنتدى

=======================================

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Jframe extends JFrame {

private JButton initialzingArray, Total,TotalCoursM,CalculatSGPA,printResult;

private Container container;

private FlowLayout layout;

public Jframe()

{

super( "Jframe" );

layout = new FlowLayout();

container = getContentPane();

container.setLayout( layout );

initialzingArray = new JButton( "initialzingArray" );

initialzingArray.addActionListener ( new ActionListener (){

public void actionPerformed (ActionEvent initialzingArray ){

// call the method that actually add the product to the database here ...

// and the other buttons need a code like this , good luck :)

}

});

container.add( initialzingArray );

Total = new JButton( "Total" );

container.add( Total );

TotalCoursM = new JButton( "TotalCoursM" );

container.add( TotalCoursM );

CalculatSGPA = new JButton( "CalculatSGPA" );

container.add( CalculatSGPA );

printResult = new JButton("printResult");

container.add( printResult );

setSize( 700, 120 );

setVisible( true );

}

public static void main( String args[] )

{

Jframe application = new Jframe();

application.setDefaultCloseOperation(

JFrame.EXIT_ON_CLOSE );

}

}====================

بالنسبة لهذا السطر

=====================

initialzingArray = new JButton( "initialzingArray" );

// my code here //

initialzingArray.addActionListener ( new ActionListener (){

public void actionPerformed (ActionEvent initialzingArray ){

// call the method that actually add the product to the database here ...

// and the other buttons need a code like this , good luck :)

========================

ابغا هذا الزر يتصل بميثود في كلاس اسمه

StudentApp

واسم الميثود الي ابغاه يتصل بها اسمها

initialzingArray

انتظر ردكم

بالتوفيق

تم تعديل هذه المشاركة بواسطة abduo_1155 في 5 مايو 2009 في 02:12

#2


public void actionPerformed (ActionEvent initialzingArray ){

//create a new StudentApp object and call the method
StudentApp std = new StudentApp();
std.initialzingArray();
}
});
initialzingArray.addActionListener ( new ActionListener (){

ما المشكل؟؟

#3

اخي داخل ActionListener بتقدر تحط اللي بدك ياه و عند الضغط على JButton يقوم باستدعاء الميثود اللذي استدعيته داخل ال ActionListener

و هناك عدة طرق لاستدعاء ال ActionListener

و المثال اللي حطو الاخ herch من النوع الانيموس او المجهول و هيك اسمو لانو حطينا كلاس داخل ActionListener من دون ما نطلق على الكلاس اسم

يعني كلاس بدون اسم

mofeedchaar@hotmail.com

#4

herch

روح يا شيخ ربي يسعدك ويعطيك الف عافيه

mofeed chaar

يعطيك الف عافيه عزيزي على ردك

ولكن هل ممكن مثال على كلامك

طيب اخواني الكرام ناقصني شيئين ازا في موضوع يشرحها او عندكم خلفيه ياريت تساعدوني

اول شي ابغا احط صوره في كلاس Jframe

ثانيا ابغا اسوي شريط التول بار مثلا File , Edit

بالتوفيق

#5

public Jframe()
{
//..............
JMenuBar menuBar = new JMenuBar(); //The menu bar
JMenu mnFile = new JMenu("File"); //the menu
JMenuItem itmExit = new JMenuItem("Exit"); //a menu item
//the action to execute when you select this menuitem
itmExit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
System.exit(0);
}
});
//add the menuitem to the menu
mnFile.add(itmExit);
//add the menu to the menu bar
menuBar.add(mnFile);
//add the menubar to the frame
setJMenuBar(menuBar);
//..............
}
//..................
 //..................

#6

herch

جزاك الله خير عزيزي كفيت ووفيت

الله يقويك ويوفقك دنيا واخره

بفضلك الله عز وجل ثم بفضلك تم ربط جميع الميثود

وتطوير المينو بار وعمل ميثود خاص فيها

اخواني الاعزاء البرنامج الحمد لله انتهى

بس باقي اضع صوره في بداية البرنامج فوق الازارير عشان يعطي منظر جمالي

انا الي فاكره من ايام زمان

اول شي الان عرفت الكلاس وعملت اوبجيكت منه في نفس كلاس ال Jframe

private Image image;

بعدين في البودي كتبت

Image image = getToolkit().getImage("dd.gif");

وحطيت الصوره في نفس مجلد البرنامج بس ما طلع

ففاكر انه ناقص شي يضيف الصوره حتى تسير ظاهره

فانتظر ردكم اخواني الكرام

بالتوفيق

#7

السلام عليكــم ورحمـة الله وبركاتــه ،،

لا توجد طريقة مباشرة لوضع صورة كخلفية لJFrame

إذا أردت فعل ذلك فعليك إعادة كتابة الميثود paintComponent(Graphics g) الخاصة بالContentPane المرتبط بالJFrame

إذا كنت لا تعلم ما هو الContentPane، زر هذه الصفحة http://java.sun.com/docs/books/tutorial/ui...s/rootpane.html

وهذا الرسم يبين الطبقات المكونة لJFrame

1layers.gif

مثال


//...............
Image image = getToolkit().getImage("img.jpg");
//We will set this JPanel as the ContentPane, and we override the paintComponent method, which is responsable of drawing the JPanel
//so it draw an image in the background
JPanel pnContentPane = new JPanel() {
JPanel pn = new JPanel(new BorderLayout()) {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
};
};
this.setContentPane(pn);
//.................
}
 public MyFrame() {

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