powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / Помогите разобраться в коде
2 сообщений из 2, страница 1 из 1
Помогите разобраться в коде
    #33826086
sahar
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Я начал учить джаву. В следуещем коде есть ошибка if ((evt.id == Event.ACTION_EVENT) && (evt.target==m) ) , m - не найдено...
Сам код

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
 import  java.awt.*;
 import  java.applet.Applet;
 public   class  MenuO  extends  Applet {
     public   void  init(){
         new  Menu_Frame();
    }
} // конец Menu1
// создаем новый экземпляр класса Menu_Frame
 class  Menu_Frame  extends  Frame {
     float  conversion_ratio =  1 .5f;
    TextField field1 =  new  TextField( 15 );
    TextArea field2 =  new  TextArea( 4 , 20 );
    TextField ratioField =  new  TextField( 5 );
    Scrollbar ratioScrollBar =  new  Scrollbar( Scrollbar.HORIZONTAL,  150 , 25 ,  50 ,  250  );
    Panel cards_panel;
     public  Menu_Frame() {
        setLayout( new  BorderLayout());
        MenuBar Bar =  new  MenuBar();
        Menu m =  new  Menu("Operation");
        m.add( new  MenuItem("Adjust Ratio"));
        m.add( new  MenuItem("Calculate"));
        Bar.add(m);
        setMenuBar(Bar);
        setFont( new  Font("Helvetica", Font.PLAIN,  12 ));
        setBackground(Color.white);
        ratioField.setEditable(false);
        field1.setEditable(true);
        field2.setEditable(false);
        ratioField.setText("1.50");
        field1.resize(field1.preferredSize());
        field2.resize(field2.preferredSize());
        ratioField.resize(ratioField.preferredSize());
        ratioScrollBar.resize(ratioScrollBar.preferredSize());
        cards_panel =  new  Panel();
        cards_panel.setLayout( new  CardLayout());
        Panel ratio_panel =  new  Panel();
        Panel calculate_panel =  new  Panel();
        ratio_panel.add(ratioField);
        ratio_panel.add(ratioScrollBar);
        calculate_panel.add(field1);
        calculate_panel.add(field2);
        cards_panel.add("Adjust Ratio", ratio_panel);
        cards_panel.add("Calculate", calculate_panel);
        add("Center", cards_panel);
        resize( 250 , 300 );
        pack();
        show();
    } // Menu_Frame
     public   void  convert() {
         float  currency1, currency2;
        String InputString = field1.getText();
        field1.setText("");
        currency1 =  Float .valueOf(InputString).floatValue();
        currency2 = conversion_ratio * currency1;
        String OutputString ="$" + InputString + " = " + "#" +
         Float .toString(currency2) + "\n";
        field2.appendText(OutputString);
    } //convert
     public   boolean  handleEvent(Event evt) {
         if  (evt.target == ratioScrollBar) {
             int  in;
            in = ratioScrollBar.getValue();
            conversion_ratio = in/100f;
            ratioField.setText( Float .toString(conversion_ratio));
        }
         if  (evt.target == field1) {
             char  c=( char )evt.key;
             if  (c == '\n'){
                convert();
                 return  true;
            }  else  { 
                 return  false; 
            }
        }
         if  ((evt.id == Event.ACTION_EVENT) && (evt.target==m) ) {
            ((CardLayout)cards_panel.getLayout()).show(cards_panel,(String)evt.arg);
             return  true;
        }
         if  (evt.id == Event.WINDOW_DESTROY) {
            dispose();
             return  true;
        }
         return  false;
    }
}

...
Рейтинг: 0 / 0
Помогите разобраться в коде
    #33826138
Фотография Кувалдин Роман
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Переменная m в твоем случае объявлена локально в конструкторе. Вне конструктора она не видна. Объяви ее после Panel cards_panel;

======================
- Я подхожу к клетке с медведем панда...
Видите, какие у него черные круги под глазами?!
Медведь панда как бы всем своим видом говорит нам: "Не бухайте!"
======================
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Помогите разобраться в коде
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]