هذا هو السؤال وهذي محاولتي حلي صحيح وطلع لي 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);
}
}