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

إلى خبراء ال GUI

مغلق
بدأه شاب مسلم في 29 مارس 2004 · 18 رد · 1,478 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

أريد فقط احد يقوم بعمل هذا البرنامج

وهذه فرصة للتعلم منه

=====

Design an implement in Java a Television Controller with a friendly graphical user interface. The program must satisfy the following constraints:

• The program should be an application that extends the JFrame class.

• All components should be swing components where possible.

• The controller should have push buttons to change the channel. A total of four channels should exist (CH1, CH2, CH3, CH4).

• A tuner panel should exist to associate a channel to a television station. The television stations are rte1, network2, tv3 and tg4. (Use JCombo-box/JList for choosing channel for a station)

• Once the tuning is done if the user clicks on a channel button an Image corresponding to that channel should appear in the “picture panel” of the GUI (Hint: add the image as an icon to a label and add the label to the picture panel). Images for the channels are provided on the student share under the folder assignment 2.

• A set of radio buttons should be present to change the display mode from colour to black and white and vice versa. Black and white and colour images are provided for each television station.

تم تعديل هذه المشاركة بواسطة شاب مسلم في 29 مارس 2004 في 23:25

#2

يمكنك وضع اي 4 صور بالالوان ونفسهم بعد عكس الالوان او جعلهم ابيض واسود

حتى نفهم الغرض تماما من هذا البرنامج

ودمتم في خير

وانتظر من يكتب لنا هذا البرنامج

#3

to use the code do as follow..

select the chanel from drop down list

then

click on the button you wont this chanel to be assign to ...

after that let the drop down list back to

select cahnel to set

..

....

if you do that , then cilck the button that you cliked befor and see the image..

repeat the process with the remaining buttons...

..

you can update the assignment of each image by repeating teh process again

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


public class TV extends JFrame{

  private JButton ChanelButtons[] = new JButton[4]; //CH1, CH2, CH3, CH4 // you can add as you like

  private JComboBox setChanel;
  private String chanelNames[] = {"Select chanel to set","rte1", "network2", "tv3" , "tg4"};

  private JCheckBox isBW; // display in Black and white

  // the color images
  private Icon ColorIcon[] = {new ImageIcon("A1.jpg"), new ImageIcon("A2.jpg"),
                              new ImageIcon("A3.jpg"), new ImageIcon("A4.jpg") };
  // the B&W images
  private Icon BWIcon[]    = {new ImageIcon("B1.jpg"), new ImageIcon("B2.jpg"),
                              new ImageIcon("B3.jpg"), new ImageIcon("B4.jpg") };

  // teh matrix where it will store teh settign of each Button
  private int ImageButtonIndex[][] = new int[ChanelButtons.length][2];
  private Point FrameSize = new Point(300,200);

  // the label where the image will post
  private JLabel label;

  // the constructer------------------------------------------------------------
  public TV()
  {
  super("TV Controler");
  int i;

  // Button configration
  for( i = 0; i < ChanelButtons.length; i ++)
    {
      setButton(ChanelButtons,i);
    }// end for loop Button configration

  // set the ImageButtonIndex tabel
  for( i=0; i < ImageButtonIndex.length; i ++)
   {
   ImageButtonIndex[0] = i;
   ImageButtonIndex[1] = -1;
   }//end for loop ImageButtonIndex tabel

   //set DropDown List
   setChanel = new JComboBox(chanelNames);
   getContentPane().add(setChanel);

   //set the check object
   isBW = new JCheckBox("Black and White only");
   getContentPane().add(isBW);

   //label setting
   label = new JLabel();
   getContentPane().add(label);

   //frame configration
   getContentPane().setLayout(new FlowLayout());
   setSize(FrameSize.x,FrameSize.y);
   setVisible(true);

  }// end constructer

  // the defualt settign of Buttons---------------------------------------------
  private void setButton(JButton Button , int ButtonNumber)
  {
  String ButtonText = new String("CH");
  ButtonText+= (ButtonNumber+1);
  Button = new JButton(ButtonText);
  Button.setActionCommand(ButtonText);
  Button.addActionListener(//S1
              new ActionListener(){//S2
                  public void actionPerformed (ActionEvent event )
                      {
                        setButtonImage(event.getActionCommand());
                      }
                      }//E2
                      );//E1

  getContentPane().add(Button);
  }// end setButton method *

  // set an image to teh buttons------------------------------------------------
  private void setButtonImage(String Button)
  {
  int i = 1;

  // find the value of teh button
  for(i = 1; i < ChanelButtons.length; i ++)
  {
    String ButtonName = new String("CH"+i);
    if(ButtonName.equals(Button)){break;}
  } // end for loop

  // change i to i-1;
  --i;

  // if the value is true
  if(i < ChanelButtons.length )
  {
   //assign value if the chanel is selected to CH#
   if(ImageButtonIndex[1] == -1)
      {
      if (setChanel.getSelectedIndex() != 0)
        {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
      }// end if ImageButtonIndex[1] == -1

  // assign new value (update)
  if(ImageButtonIndex[1] != -1)
     {
     if (setChanel.getSelectedIndex() != 0)
         {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
      }// end if ImageButtonIndex[1] == 1

  // Show the image
  if(ImageButtonIndex[1] != -1)
     {
     if (setChanel.getSelectedIndex() == 0)
         {setBackground(ImageButtonIndex[1]);}
      }// end if ImageButtonIndex[1] == 1


  }



  }// end method setButtonImage *

  // set back ground------------------------------------------------------------
  private void setBackground(int ImageIndex)
  {
  ImageIndex--;

  if(isBW.isSelected())
       {
         label.setIcon(BWIcon[ImageIndex]);
         FrameSize.x =BWIcon[ImageIndex].getIconWidth();
         FrameSize.y =BWIcon[ImageIndex].getIconHeight();
       }

  else{
     label.setIcon(ColorIcon[ImageIndex]);
     FrameSize.x =ColorIcon[ImageIndex].getIconWidth();
     FrameSize.y =ColorIcon[ImageIndex].getIconHeight();
      }

  repaint();

    setSize(FrameSize.x+250,FrameSize.y+110);
  }//end method setBackground*

  //the main method-------------------------------------------------------------
  public static void main(String[] args) {

      TV test = new TV();
      test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



    }//end the main method


}// end class
#4

الان بجربه وسوف ارد عليك

#5

أخي الكريم تقريبا البرنامج كما يريدون بالضبط

إلا أنه هناك نقطه واحده تختلف عن البرنامج الذي قمت مشكورا بعمله

هم يريدون ان تكون هناك قائمتان منسدلتان ولكنهما مختفيتان

وتعمل Button وتسميه Tune

إذا ضغط المستخدم على Tune

تظهر له القائمتان المختفيتان

واحده فيها CH1, CH2, CH3, CH4

والثانية فيها

"rte1", "network2", "tv3" , "tg4"

ويضغط المسختدم على رقم القناة ويضع فيها اسم التلفزيون

حتى يخزن اسماء التلفزيونات على الارقام التي يحبها

فإذا ضغط مرة ثانية على

Tune

يتم حفظ التعديلات التي قام بها وكذلك تختفي القوائم

ويفضل ان تكون هذه القوائم وزر Tune أسفل الشاشة

ودمتم في خير

==========

وان كان الكود الذي قمت بعمله بارك الله فيك يقوم بنفس الغرض

وفعلا مستوى الكود مرتفع جدا

#6

هذا الكود مرة ثانية بعد ان وضعت فيه اسماء القنوات

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


public class TV extends JFrame{

 private JButton ChanelButtons[] = new JButton[4]; //CH1, CH2, CH3, CH4 // you can add as you like

 private JComboBox setChanel;
 private String chanelNames[] = {"Select chanel to set","rte1", "network2", "tv3" , "tg4"};

 private JCheckBox isBW; // display in Black and white

 // the color images
 private Icon ColorIcon[] = {new ImageIcon("rte1.jpg"), new ImageIcon("net2.jpg"),
                             new ImageIcon("tv3.jpg"), new ImageIcon("tg4.jpg") };
 // the B&W images
 private Icon BWIcon[]    = {new ImageIcon("bwrte1.jpg"), new ImageIcon("bwnet2.jpg"),
                             new ImageIcon("bwtv3.jpg"), new ImageIcon("bwtg4.jpg") };

 // teh matrix where it will store teh settign of each Button
 private int ImageButtonIndex[][] = new int[ChanelButtons.length][2];
 private Point FrameSize = new Point(500,500);

 // the label where the image will post
 private JLabel label;

 // the constructer------------------------------------------------------------
 public TV()
 {
 super("TV Controler");
 int i;

 // Button configration
 for( i = 0; i < ChanelButtons.length; i ++)
   {
     setButton(ChanelButtons,i);
   }// end for loop Button configration

 // set the ImageButtonIndex tabel
 for( i=0; i < ImageButtonIndex.length; i ++)
  {
  ImageButtonIndex[0] = i;
  ImageButtonIndex[1] = -1;
  }//end for loop ImageButtonIndex tabel

  //set DropDown List
  setChanel = new JComboBox(chanelNames);
  getContentPane().add(setChanel);

  //set the check object
  isBW = new JCheckBox("Black and White only");
  getContentPane().add(isBW);

  //label setting
  label = new JLabel();
  getContentPane().add(label);

  //frame configration
  getContentPane().setLayout(new FlowLayout());
  setSize(FrameSize.x,FrameSize.y);
  setVisible(true);

 }// end constructer

 // the defualt settign of Buttons---------------------------------------------
 private void setButton(JButton Button , int ButtonNumber)
 {
 String ButtonText = new String("CH");
 ButtonText+= (ButtonNumber+1);
 Button = new JButton(ButtonText);
 Button.setActionCommand(ButtonText);
 Button.addActionListener(//S1
             new ActionListener(){//S2
                 public void actionPerformed (ActionEvent event )
                     {
                       setButtonImage(event.getActionCommand());
                     }
                     }//E2
                     );//E1

 getContentPane().add(Button);
 }// end setButton method *

 // set an image to teh buttons------------------------------------------------
 private void setButtonImage(String Button)
 {
 int i = 1;

 // find the value of teh button
 for(i = 1; i < ChanelButtons.length; i ++)
 {
   String ButtonName = new String("CH"+i);
   if(ButtonName.equals(Button)){break;}
 } // end for loop

 // change i to i-1;
 --i;

 // if the value is true
 if(i < ChanelButtons.length )
 {
  //assign value if the chanel is selected to CH#
  if(ImageButtonIndex[1] == -1)
     {
     if (setChanel.getSelectedIndex() != 0)
       {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
     }// end if ImageButtonIndex[1] == -1

 // assign new value (update)
 if(ImageButtonIndex[1] != -1)
    {
    if (setChanel.getSelectedIndex() != 0)
        {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
     }// end if ImageButtonIndex[1] == 1

 // Show the image
 if(ImageButtonIndex[1] != -1)
    {
    if (setChanel.getSelectedIndex() == 0)
        {setBackground(ImageButtonIndex[1]);}
     }// end if ImageButtonIndex[1] == 1


 }



 }// end method setButtonImage *

 // set back ground------------------------------------------------------------
 private void setBackground(int ImageIndex)
 {
 ImageIndex--;

 if(isBW.isSelected())
      {
        label.setIcon(BWIcon[ImageIndex]);
        FrameSize.x =BWIcon[ImageIndex].getIconWidth();
        FrameSize.y =BWIcon[ImageIndex].getIconHeight();
      }

 else{
    label.setIcon(ColorIcon[ImageIndex]);
    FrameSize.x =ColorIcon[ImageIndex].getIconWidth();
    FrameSize.y =ColorIcon[ImageIndex].getIconHeight();
     }

 repaint();

   setSize(FrameSize.x+450,FrameSize.y+410);
 }//end method setBackground*

 //the main method-------------------------------------------------------------
 public static void main(String[] args) {

     TV test = new TV();
     test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



   }//end the main method


}// end class
#7

كذلك هناك نقطه اخرى

هم يريدون

Radio Buttons

واحد مخصص للأبيض والاسود

والثاني للألوان

وهو ينتقل بينهم

اعلم انك قمت بنفس الفكرة المطلوبة عن طريق

Checkbox

فأتمنى التغيير كما يريدون

وبارك الله فيك اخي الكريم

#8
اقتباس
فأتمنى التغيير كما يريدون

Mr. ShapMuslim , the point of the Forum ArabTeam 2000 is to LEARN not to solve

home works .. :(

i think that the programm is 95% solved ... so since you mention that you need to learn

اقتباس
وهذه فرصة للتعلم منه

so , try to do the modification by your self ... and show us your work ... and for sure we will help you at then ...

Good luke in your HOME WORKS ...

#9

أخي الكريم ومن قال لك اني سوف أقدم هذا الكود على انه مشروع خاص بي

اني سوف اضع الكود الخاص بي بعد ان انتهي منه ؛ سوف أضعه هنا في المنتدى

ولكن انا اريد ان اتعلم نقطه في كيفية اخفاء القائمة

وسبق لي قبل مرة ان سألت عن مشروع مشابه ولكن حينما قدمته كان يختلف كليا عن الذي كتب لي هنا ؛ وهو مشروع arry

ولكن فقط احيانا يكون صعب الوصول للفكرة وحينما يتم طرح البرنامج اصل لحل لبعض المشاكل التي أواجهها في الكود الذي أقوم به .

هذا الذي اريد ان اقوله

تم تعديل هذه المشاركة بواسطة شاب مسلم في 31 مارس 2004 في 15:55

#10
اقتباس
ولكن انا اريد ان اتعلم نقطه في كيفية اخفاء القائمة

to do sow for the drop down list

setChanel.setVisible(false);

if false , then it will disapear , for true it will appear

#11
private void setButtonImage(String Button)
 {
 int i = 1;

 // find the value of teh button
 for(i = 1; i < ChanelButtons.length; i ++)
 {
   String ButtonName = new String("CH"+i);
   if(ButtonName.equals(Button)){break;}
 } // end for loop

 // change i to i-1;
 --i;

 // if the value is true
 if(i < ChanelButtons.length )
 {
  //assign value if the chanel is selected to CH#
  if(ImageButtonIndex[1] == -1)
     {
     if (setChanel.getSelectedIndex() != 0)
       {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
     }// end if ImageButtonIndex[1] == -1

 // assign new value (update)
 if(ImageButtonIndex[1] != -1)
    {
    if (setChanel.getSelectedIndex() != 0)
        {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
     }// end if ImageButtonIndex[1] == 1

 // Show the image
 if(ImageButtonIndex[1] != -1)
    {
    if (setChanel.getSelectedIndex() == 0)
        {setBackground(ImageButtonIndex[1]);}
     }// end if ImageButtonIndex[1] == 1

ممكن تشرح لي اخي الكريم هذا الجزء من البرنامج

انا فهمت كل البرنامج

ولكن هذا الجزء عجزت عن افهمه بشكل صحيح

#12

give me you attention

1)

private void setButtonImage(String Button)
{
int i = 1;

// find the value of teh button
for(i = 1; i < ChanelButtons.length; i ++)
{
  String ButtonName = new String("CH"+i);
  if(ButtonName.equals(Button)){break;}
} // end for loop

for each button there is a name CH1 , CH2 , CH3 , CH4

but we don't know which one has been clicked ...

2)

// change i to i-1;
--i;

the name of button start from CH1 but array start from 0 ... so reduce index by 1

3)

// if the value is true
if(i < ChanelButtons.length )
{
 //assign value if the chanel is selected to CH#
 if(ImageButtonIndex[1] == -1)
    {
    if (setChanel.getSelectedIndex() != 0)
      {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
    }// end if ImageButtonIndex[1] == -1

if(ImageButtonIndex[1] == -1 then it has not been assign to any value before

if (setChanel.getSelectedIndex() != 0) then the user has select an image name

4)

// assign new value (update)
if(ImageButtonIndex[1] != -1)
   {
   if (setChanel.getSelectedIndex() != 0)
       {ImageButtonIndex[1] = setChanel.getSelectedIndex();}
    }// end if ImageButtonIndex[1] == 1

nearly teh same as 3) but for update purpose

5)

// Show the image
if(ImageButtonIndex[1] != -1)
   {
   if (setChanel.getSelectedIndex() == 0)
       {setBackground(ImageButtonIndex[1]);}
    }// end if ImageButtonIndex[1] == 1

to assign an image to the frame background

#13

ياخي والله الرجال ماقصر معاك

اعطاك كل الي تريد والان تتشرط عليه

والله انا قهرت !!!!!!!!!

لو انا مكطانك بحمد الله

abo_alzobaer@hotmail.com

#14

الاخ mgazif انت ليش انقهرت بعدين نحن هنا لكي نساعد بعضنا و ليس لكي نتشاطر و نلعب فتوة و استعراض عضلات...

اخي شاب مسلم ممكن تعطيني المسنجر مالك ضروري جدا

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#15

ياخي لو انا غلطان انا اسف

لكن الموضوع انحل بنسبة 99% والمفروض ان الباقي يكون عليك

ولاتزعل مني

abo_alzobaer@hotmail.com

#16

يا اخي الكريم انا ما قلت شيء الرجل ساعدني فعلا

ولكن هناك جزء من الكود لم افهمه

والغايه من وضع الكود ليس ان احل المشكلة او السؤال او احد يضع لي الحل

الغايه هي ان افهم كيف كتبته وما هي وظيفه كل سطر

وهذا ما طلبته في توضيحي الاخير

اما بالنسبة للماسنجر الخاص بي فهو

====

telfax7@hotmail.com

ولكن بعد الامتحانات التي ستبدا بعد ثلاثة اسابيع و ستكون الاختبارات عشرة ايام

ودمتم في خير

#17

mgazif

thank you for your feeling . .. but the object of this form is to learn and learn more

we share our knowledg and experiance ...

شاب مسلم

i hope that the code is clear now ... if not aske me again ...

and beast weshes in your exames ...

....

again ... any unclear part in my code just ask

#18
المبرمج1 كتب:
mgazif

thank you for your feeling . .. but the object of this form is to learn and learn more

we share our knowledg and experiance ...

شاب مسلم

i hope that the code is clear now ... if not aske me again ...

and beast weshes in your exames ...

....

again ... any unclear part in my code just ask

جزاكم الله خيرا اخي الكريم المبرمج 1

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

وبارك الله فيك على مجهودك معي

#19

اقتباس
وفي واقع الامر الكود فهمته الان بشكل اوضح

this is the our goal .... to learn and share owr knoledg ..

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

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

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

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

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

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