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

الى خبراء الـ GUI

بدأه mgaa في 29 مايو 2012 · 1 رد · 486 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

كنت عايز شرح مفصل للبرنامج دا كل Statement بتعمل ايه بالظبط

001 import java.awt.*;

002 import javax.swing.*;

003 import java.awt.event.*;

004

005

006 public class DrawArcs extends JFrame

007 {

008

009 public JPanel speedPanel;

010 public JPanel fanPanel;

011 public JPanel boxPanel;

012 public JButton lowBtn;

013 private JButton midBtn;

014 private JButton highBtn;

015 private String onString = "On";

016 private String lowString = "Low";

017 private String midString = "Mid";

018 private String highString = "High";

019 Timer timer;

020

021

022 private class TimerListener implements ActionListener

023 {

024 public void actionPerformed(ActionEvent e)

025 {

026 repaint();

027

028

029 }

030 }

031

032 public static void main (String [] args)

033 {

034

035 DrawArcs frame = new DrawArcs();

036 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

037 frame.setSize(400, 400);

038 frame.setLocationRelativeTo(null);

039 frame.setVisible(true);

040

041

042

043

044 }

045

046 public DrawArcs()

047 {

048 //timer = new Timer(speed, new TimerListener());

049

050 setTitle("Box Fan");

051 setLayout(new BorderLayout());

052

053 getContentPane().add(new ArcsPanel(), BorderLayout.CENTER);

054

055 choicePanel();

056

057

058 }

059 public void time(int speed)

060 {

061

062 timer = new Timer(speed, new TimerListener());

063 timer.start();

064

065 }

066

067

068 public void choicePanel()

069 {

070

071 ButtonListener choiceBtn = new ButtonListener();

072

073 JRadioButton lowButton = new JRadioButton(lowString);

074 lowButton.setActionCommand(lowString);

075

076

077 JRadioButton midButton = new JRadioButton(midString);

078 midButton.setActionCommand(midString);

079

080

081 JRadioButton highButton = new JRadioButton(highString);

082 highButton.setActionCommand(highString);

083

084

085 //Group the radio buttons.

086 ButtonGroup group = new ButtonGroup();

087

088 group.add(lowButton);

089 group.add(midButton);

090 group.add(highButton);

091

092

093 //Register a listener for the radio buttons.

094

095 lowButton.addActionListener(choiceBtn);

096 midButton.addActionListener(choiceBtn);

097 highButton.addActionListener(choiceBtn);

098

099 speedPanel = new JPanel();

100

101 speedPanel.add(lowButton);

102 speedPanel.add(midButton);

103 speedPanel.add(highButton);

104

105

106 add(speedPanel, BorderLayout.WEST);

107

108

109

110 }

111 public class ButtonListener implements ActionListener

112 {

113 int count=0;

114 //count++;

115 public void actionPerformed(ActionEvent e)

116 {

117

118 if(e.getActionCommand().equals("Low"))

119 {

120 count++;

121 if(count==1)

122 {

123

124 time(150);

125 }

126

127 else if (count>1)

128 {

129 timer.start();

130 timer.stop();

131 time(150);

132 }

133 }

134

135 else if (e.getActionCommand().equals("Mid"))

136 {

137 timer.start();

138 timer.stop();

139 time(65);

140

141 }

142

143 else if (e.getActionCommand().equals("High"))

144 {

145 timer.start();

146 timer.stop();

147 time(20);

148

149 }

150 }

151 }

152

153 class ArcsPanel extends JPanel

154 {

155 double currentTheta;

156 public void paintComponent(Graphics g)

157 {

158 super.paintComponent(g);

159

160 Graphics2D g2d = (Graphics2D) g;

161

162 currentTheta =currentTheta -1;

163

164 int xCenter = 0;

165 int yCenter = 0;

166

167 int radius = (int) (Math.min(getWidth(), getHeight()) * 0.4);

168 int x = xCenter - radius;

169 int y = yCenter - radius;

170 int sLength = (int) (radius * 0.8);

171

172

173 g2d.translate(this.getWidth() / 2, this.getHeight() / 2);

174

#2

يا ريت تحدد اللى انت عايزه بالظبط لان اللى انت كاتبه ده مينفعش حد يشرحه والا هيقعد اسبوع يشرح فيه

001 import java.awt.*;
002 import javax.swing.*;
003 import java.awt.event.*;
004 
005 
006 public class DrawArcs extends JFrame 
007 {
008 
009 public JPanel speedPanel;
010 public JPanel fanPanel;
011 public JPanel boxPanel;
012 public JButton lowBtn;
013 private JButton midBtn;
014 private JButton highBtn;
015 private String onString = "On";
016 private String lowString = "Low";
017 private String midString = "Mid";
018 private String highString = "High";
019 Timer timer;
020 
021 
022 private class TimerListener implements ActionListener
023 {
024 public void actionPerformed(ActionEvent e)
025 {
026 repaint();
027 
028 
029 }
030 }
031 
032 public static void main (String [] args)
033 {
034 
035 DrawArcs frame = new DrawArcs();
036 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
037 frame.setSize(400, 400);
038 frame.setLocationRelativeTo(null);
039 frame.setVisible(true);
040 
041 
042 
043 
044 }
045 
046 public DrawArcs()
047 {
048 //timer = new Timer(speed, new TimerListener());
049 
050 setTitle("Box Fan");
051 setLayout(new BorderLayout());
052 
053 getContentPane().add(new ArcsPanel(), BorderLayout.CENTER);
054 
055 choicePanel();
056 
057 
058 }
059 public void time(int speed)
060 {
061 
062 timer = new Timer(speed, new TimerListener());
063 timer.start();
064 
065 }
066 
067 
068 public void choicePanel()
069 {
070 
071 ButtonListener choiceBtn = new ButtonListener();
072 
073 JRadioButton lowButton = new JRadioButton(lowString);
074 lowButton.setActionCommand(lowString);
075 
076 
077 JRadioButton midButton = new JRadioButton(midString);
078 midButton.setActionCommand(midString);
079 
080 
081 JRadioButton highButton = new JRadioButton(highString);
082 highButton.setActionCommand(highString);
083 
084 
085 //Group the radio buttons.
086 ButtonGroup group = new ButtonGroup();
087 
088 group.add(lowButton);
089 group.add(midButton);
090 group.add(highButton);
091 
092 
093 //Register a listener for the radio buttons.
094 
095 lowButton.addActionListener(choiceBtn);
096 midButton.addActionListener(choiceBtn);
097 highButton.addActionListener(choiceBtn);
098 
099 speedPanel = new JPanel();
100 
101 speedPanel.add(lowButton);
102 speedPanel.add(midButton);
103 speedPanel.add(highButton);
104 
105 
106 add(speedPanel, BorderLayout.WEST);
107 
108 
109 
110 }
111 public class ButtonListener implements ActionListener
112 {
113 int count=0;
114 //count++;
115 public void actionPerformed(ActionEvent e) 
116 {
117 
118 if(e.getActionCommand().equals("Low"))
119 {
120 count++;
121 if(count==1)
122 {
123 
124 time(150);
125 }
126 
127 else if (count>1)
128 {
129 timer.start();
130 timer.stop();
131 time(150);
132 }
133 }
134 
135 else if (e.getActionCommand().equals("Mid"))
136 {
137 timer.start();
138 timer.stop();
139 time(65);
140 
141 }
142 
143 else if (e.getActionCommand().equals("High"))
144 {
145 timer.start();
146 timer.stop();
147 time(20);
148 
149 } 
150 }
151 }
152 
153 class ArcsPanel extends JPanel
154 {
155 double currentTheta;
156 public void paintComponent(Graphics g) 
157 {
158 super.paintComponent(g);
159 
160 Graphics2D g2d = (Graphics2D) g;
161 
162 currentTheta =currentTheta -1;
163 
164 int xCenter = 0;
165 int yCenter = 0;
166 
167 int radius = (int) (Math.min(getWidth(), getHeight()) * 0.4);
168 int x = xCenter - radius;
169 int y = yCenter - radius;
170 int sLength = (int) (radius * 0.8);
171 
172 
173 g2d.translate(this.getWidth() / 2, this.getHeight() / 2);
174

الكود كده اوضح صح ولا ايه ؟

تم تعديل هذه المشاركة بواسطة mohamed salama في 31 مايو 2012 في 21:09

73b14eadba.gif

الحمدلله والصلاة والسلام على رسول الله وعلى آله وصحبه أجمعين

لكل مبتدئى البرمجه برمجه بلغه السى شارب

تنصيب ويندوز 8 على vmware

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

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

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

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

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