问答题
本题中,在下画线上填写代码,指定变量b为字节型,变量f为单精度实型,变量1为64位整型。
public class java1
public static void main(String[]args)
______b=49;
______f=8.9f;
______l=0xfedl;
System.out.println("b="+b);
System.out.println("f="+f);
System.out.println("l="+1);
【参考答案】
第1处:byte
第2处:float
第3处:long
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
本题中,通过菜单“Connect”显示一个对话框,单击“ok”按钮后,所填写的内容就会传回到主窗口并显示出来。 import java.awt.*; import java.awt.event.*; import javax.swing.*; public class java3 extends JFrame implements ActionListener public java3() setTitle( java3 ); setSize(300,300); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); JMenuBar mbar=new JMenuBar(); setJMenuBar(bar); JMenu fileMenu=new JMenu( File ); mbar.add(fileMenu); connectItem=new JMenuItem( Connect ); connectItem.addActionListener(this); fileMenu.add(connectItem); exitItem=new JMenuItem( Exit ); exitItem.addActionListener(this); fileMenu.add(exitItem); public void actionPerformed(ActionEvent evt) Object source=evt.getSource(); if(source==connectItem) ConnectInfo transfer=new ConnectInfo( yourname , pw ); if(dialog==null) dialog=new ConnectDialog(this); if(dialog.showDialog(transfer)) String uname=transfer.username; String pwd=transfer.password; Container contentPane=getContentPane(); contentPane.add(new JLabel( username= +uname+ ,password= +pwd), South ); validate(); else if(source==exitItem) System.exit(0); public static void main(String[]args) JFrame f=new java3(); f.show(); private ConnectDialog dialog=null; private JMenuItem connectItem; private JMenuItem exitItem; class ConnectInfo public String username; public String password; public Connectfnfo(String u,String p) username=u;password=p; class ConnectDialog extends JDialog implements ActionListener public ConnectDialog() super(parent, Connect ,true); Container contentPane=getContentPane(); JPanel p1=new JPanel(); p1.setLayout(new GridLayout(2,2)); p1.add(new JLabel( User name: )); p1.add(username=new JTextField( )); p1.add(new JLabel( Password: )); p1.add(password=new JPasswordField( )); contentPane.add( Center ,p1); Panel p2=new Panel(); okButton=addButton(p2, Ok ); cancelButton=addButton(p2, Cancel ); contentPane.add( South ,p2); setSize(240,120); JButton addButton(Container c,String name) JButton button=new JButton(name); button.addActionListener(this); c.add(button); return button; public void actionPerformed(ActionEvent evt) Object source=evt.getSource(); if(source==okButton) ok=true; setVisible(false); else if(source==cancelButton) setVisible(false); public void showDialog(ConnectInfo transfer) username.setText(transfer.username); password.setText(transfer.password); ok=false; show(); if(ok) transfer.username=username.getText(); transfer.password=new String(password.getPassword()); return ok; private JTextField username; private JPasswordField password; private boolean ok; private JButton okButton; private JButton cancelButton;
点击查看答案&解析
多项选择题
本题是一个表格式的成绩单,其中包括“姓名”、“英语成绩”、“数学成绩”和“总成绩”,姓名和成绩都可以进行修改,单击按钮“计算每人总成绩”,则可以统计出每个人的总成绩并显示在总成绩栏中。 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class java2 extends JFrame implements ActionListener JTable table;Object a[][]; Object name[]= 姓名 , 英语成绩 , 数学成绩 , 总成绩 ); JButton button; java2() setTitle( java2 ); a=new Object[8][4]; for(int i=0;i<8;i++) for(int j=0;j<4;j++) if(j!=0) a[i][j]= ; else a[i][j]= ; button=new JButton( 计算每人总成绩 ); table=______; button.addActionListener(this); getContentPane().add(new JScrollPane(table),BorderLayout.CENTER); getContentPane().add(button,BorderLayout.SOUTH); setSize(400,200); setVisible(true); validate(); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); public void actionPerformed(ActionEvent e) for(int i=0;i<8;i++) double sum=0; boolean boo=true; for(int j=1;j<=2;j++) try sum=sum+Double.parseDouble(______); catch(Exception ee) boo=false; table.repaint(); if(boo==true) a[i][3]= +sum; table.repaint(); public static void main(String args[]) java2 Win=new java2();
点击查看答案&解析
相关试题
本题中,通过菜单“Connect”显示一个对话...
本题是一个表格式的成绩单,其中包括“姓名...