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

[ تمت الإجابة ]لو سمحتوا ابي مساعده في هذا الكود....

بدأه AboOoOora في 28 مايو 2011 · 4 رد · 467 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذا هو السؤال وهذي محاولتي حلي صحيح وطلع لي output وطلع frame الي طلبته بس لازم اذا ضغطت على background يتغير اللون واذا ادخلت text في text field يتغير العنوان ماني عارفه كيف ..ممكن مساعدتكم وشكرا

Q:Design a frame that contain one text field and one button as Shown below, when you click the button the background color will change, and when you enter text in the text field the Title will change as shown below, use the appropriate layout.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class ch14jButton extends JFrame

{

private static final int FRAEM_WIDTH=300;

private static final int FRAEM_HEIGHT=200;

private static final int FRAEM_X_ORIGIN=150;

private static final int FRAEM_Y_ORIGIN=250;

private JTextField inputLine;

public static void main (String args[])

{ ch14jButton frame=new ch14jButton();

frame.setVisible(true);

}

public ch14jButton(){

Container contentpane=getContentPane();

JButton Background;

setSize(FRAEM_WIDTH,FRAEM_HEIGHT);

setTitle("your name");

setLocation(FRAEM_X_ORIGIN,FRAEM_Y_ORIGIN);

contentpane.setLayout(new BorderLayout());

Background=new JButton("Background");

inputLine=new JTextField();

contentpane.add(Background,BorderLayout.SOUTH);

contentpane.add(inputLine,BorderLayout.NORTH);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

}

#2

مراحب آنسة AboOoOora

هذا هو الكود الجديد لبرنامجك معدل

ولكن يرجى الانتباه ... انه إذا قمتي بالضغط على زر تغيير لون الخلفية فإنك سوف لن تلاحظي تغيرها على الفريم

لأنه يوجد مشكلة مع ال IDEs في هذه النقطة

فلذلك ... يجب عليكي اضافة Panel وسوف تلاحظي تغير لون الخلفية

وبالنسبة للـ TextField فبمجرد كتابتك للنص والضغط على زر Enter على الكيبورد فإنه سوف يقوم بتغيير عنوان الفريم

تحياتي

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class ch14jButton extends JFrame implements ActionListener {

private static final int FRAEM_WIDTH=300;
private static final int FRAEM_HEIGHT=200;
private static final int FRAEM_X_ORIGIN=150;
private static final int FRAEM_Y_ORIGIN=250;

private JTextField inputLine;

public ch14jButton(){
Container contentpane=getContentPane();
JButton Background;

setSize(FRAEM_WIDTH,FRAEM_HEIGHT);
setTitle("your name");
setLocation(FRAEM_X_ORIGIN,FRAEM_Y_ORIGIN);

contentpane.setLayout(new BorderLayout());
Background=new JButton("Background");
Background.addActionListener(this);
inputLine=new JTextField();
inputLine.addActionListener(this);

contentpane.add(Background,BorderLayout.SOUTH);
contentpane.add(inputLine,BorderLayout.NORTH);

setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public static void main (String args[]) {
ch14jButton frame=new ch14jButton();
frame.setVisible(true);
}

public void actionPerformed(ActionEvent eve) {
if(eve.getSource()==Background)
setBackground(Color.RED);
if(eve.getSource()==inputLine)
setTitle(inputLine.getText());
}
}

تم تعديل هذه المشاركة بواسطة adiga_sy في 29 مايو 2011 في 09:58

1
#3

مشكووووووووووووور اخوي وماقصرت جزاك الله الف خير

#4

لحل مشكلة تغيير لون الخلفية

لاتقومي بتغيير لون خلفية الـ

Frame

بل قومي بتغيير لون خلفية الـ

Pane

لانها تكون حاجبة كامل الفريم

يكون تغيير لون خلفية الـ

Pane

كالتالي

this.getContentPane().setBackground(Color.RED);
#5

فعلا ضبطت وتغير اللون

مدري كيف اشكرك ع الاهتمام بالموضوع

واتمنى مأكون اخذت من وقتك.........

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…