b[j][i]=a[i][j];
}
}
returnb;
}
第二题:
图形用户界面设计题
1、完成界面设计(界面的设计:
JFrame;布局:
FlowLayout、BorderLayout、GridLayout、CardLayout,null;常用组件:
JLabel、JTextField、JButton、JTextArea、JPanel……;事件处理)
(1)JFrame的应用
importjava.awt.*;
importjavax.swing.*;
classMFrameextendsJFrame{
MFrame(Strings){
super(s);
//布局
//组件创建与加载
this.pack();//this.setSize(300,200);this.setBounds(300,200,400,500);
this.setVisible(true);
this.setDefaultColoseOperation(JFrame.EXIT_ON_COLOSE);
}
}
举例:
2009年1月、2010年1月、2014年4月、2015年10月、2016
年10月最后一题
(2)事件的处理actionEvent
importjava.awt.*;
importjavax.swing.*;
importjava.awt.event.*;
classMFrameextendsJFrameimplementsActionListener{
MFrame(Strings){
super(s);
//布局
//组件创建与加载
//为事件源添加监视器
this.pack();//this.setSize(300,200);
this.setBounds(300,200,400,500);
this.setVisible(true);
this.setDefaultColoseOperation(JFrame.EXIT_ON_COLOSE);
}
//重写事件处理的方法
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==事件源对象){
//具体的事件处理内容
}
}
}
举例:
2013年10月
(3)事件处理中的两种常见问题:
a、文本框中数字的运算
doublec=Doble.parseDouble(text1.getText());//将文本框的内容转换为数字
doublef=c*9/5+32;
text2.setText(f+””);//text2.setText(String.valueOf(h));//将运算结果转换为字符串写回文本框
举例:
2010年10月、2011年1月
b、字符串的分析
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==button){
Strings=textA.getText();doublesum=0;
StringTokenizerfenxi=newStringTokenizer(s,",\n");//创建字符串分析对象
while(fenxi.hasMoreTokens()){//循环访问分析后的子串
sum=sum+Double.parseDouble(fenxi.nextToken());//将子串转换为数字参与运算
}
textA.setText(sum+””);//将结果写回文本框
}
}
举例:
2009年10月、2012年1月、2012年10月、2015年4月
(资料素材和资料部分来自网络,供参考。
可复制、编制,期待你的好评与关注)