单项选择题
下列标识符(名字)命名原则中,正确的是( )。
A.类名的首字母小写
B.变量和方法名的首字母大写
C.接口名的首字母小写
D.常量完全大写
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。 import java.awt.*; import java.awt.event.*; import javax.swing.*; class PlafPanel extends JPanel implements ActionLis- tener {public () {metaIButton=new JButton( Metal ); motifButtOn=new J Button( Motif ); windowsButton=new JButton( Windows ); add(metalButton); add(motifButton); add(windowsButton); metalButton.addActionListener(this); motifButton.addActionListener(this); windowsButton.addActionListener(this); } Dublic void actionPerformed(ActionEvent evt) {Object source=evt.getSource(); String plaf= : if(source= =metalButton) plaf= javax.swing.plaf.metal.MetalLookAnd- Feel ; else if(source= =motifButton) plaf= com.sun.java.swing.plaf.motif.Moti- fLookAndFeel ; else if(source= =windowsButton) Dlaf= com.sun.java.swing.plaf.windows.Win- dowsLookAndFeel ; try {UIManager.setLookAndFeel( ); SwingUtilities.updateComponentTreeUI(this); } catch(Exception e){) } private JButton metalButton; private JButton motifButton; private JButton windowsButton; } class PlafFrame extends JFrame {public PlafFrame() { setTitle( simple ); setSize(300,200); addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(O); } }); Container contentPane=getContentPane(); contentPane.add(new PlafPanel()); } } public class java2 {public static void main(String[]args) f JFrame frame=new PlafFrame(); frame.show(); }
点击查看答案&解析
问答题
本题中定义了一个长度为20的整数数组,然后将1~20分别赋给数组元素,计算该数组中所有下标为奇数的元素的和。 public class javal{ public static void main(String args[]){ int sum; ; int arrayList[]=new int[20]; for(int i=0;i<=19;i++) arrayList[i]=i+1; int pos=0; while(pos<20){ if( ) sum=sum+arrayList[pos]; ; } System.out.println( sum= +sum); } }
点击查看答案&解析
相关试题
下列事件监听器中,无法对TextField对象进...
本程序的功能是获取文本框中的文本。窗口中...
Java语言使用的字符码集是( )。