问题描述
下拉列表事件处理好像不对,处理不了;具体要求:可以显示Sin,Cos或绝对值数学函数的图形界面A.具有选择函数的下拉列表,X轴坐标轴的区间选择输入框,“画图”和“清除”按钮的图形界面B.点击“画图”按钮,显示函数曲线;点击“清除”按钮,清除函数曲线现在编写了框架,差画图但是框架到底哪里出问题了呢?初学者肯能看不懂解释最好能给代码!importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;classthirdextendsJFrame{intm,n;JTextFieldtextField1,textField2;//定义文本框JLabellabel1,label2;//定义x值标签JButtonbutton1,button2;StringplaceName[]={"sin","cos","绝对值"};JComboBoxplaceBox;Stringplace="";publicthird(){super("函数图像");Containercontainer=getContentPane();container.setLayout(newFlowLayout());label1=newJLabel("x值起点:");//创建标签textField1=newJTextField(5);//创建文本框textField1.addActionListener(newNewActionListener());container.add(label1);container.add(textField1);label2=newJLabel("x值终点:");//创建标签textField2=newJTextField(5);textField2.addActionListener(newNewActionListener());container.add(label2);container.add(textField2);placeBox=newJComboBox(placeName);placeBox.addItemListener(newComboListener());container.add(placeBox);//按钮创建、添加button1=newJButton("画图");//创建画图按钮button2=newJButton("清除");//创建清除按钮button1.addActionListener(newNewActionListener());button2.addActionListener(newNewActionListener());container.add(button1);container.add(button2);setSize(500,500);setVisible(true);}classComboListenerimplementsItemListener{publicvoiditemStateChanged(ItemEvente){place=(String)e.getItem();}}classNewActionListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){if(e.getSource()==button1){}elseif(e.getSource()==textField1){}elseif(e.getSource()==button2){}elseif(e.getSource()==textField2){}}}publicstaticvoidmain(Stringargs[]){thirdCH5FMP=newthird();CH5FMP.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}}