我马上JAVA考试这3个题目据考得几率大,各位帮我速度编程下面的题目,一定高分悬赏啊,急用!!!

2024-12-14 01:36:22
推荐回答(1个)
回答1:

第3题没看明白 最好给我发个大概示意图,谢谢
邮箱citytalent@126.com或者百度短信也可以

第一题
public class Test1 {
public Test1() {
System.out.println("这个是无参数构造器,类已创建");
}

public Test1(String s) {
System.out.println("这个是代一个String参数的构造器,传入的参数是:" + s + ",类已经创建");
}

public static void main(String[] args) {
Test1 t1 = new Test1();
System.out.println("=========分割=========");
Test1 t2 = new Test1("1234567");

}
}

第二题:
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.acl.Group;

import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;

public class Test2 extends Frame implements ActionListener{
ButtonGroup group = new ButtonGroup();
JRadioButton jrb1 =new JRadioButton("普通");
JRadioButton jrb2 =new JRadioButton("黑体");
JRadioButton jrb3 =new JRadioButton("斜体");
Button bt = new Button("按钮");
public Test2() {
jrb1.addActionListener(this);
jrb2.addActionListener(this);
jrb3.addActionListener(this);
setLayout(new GridLayout());
group.add(jrb1);
group.add(jrb2);
group.add(jrb3);
add(jrb1);
add(jrb2);
add(jrb3);
add(bt);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jrb1){
bt.setFont(new Font("宋体",Font.PLAIN, 12));
//System.out.println("普通");
}
if (e.getSource() == jrb2){
bt.setFont(new Font("黑体",Font.PLAIN, 12));
//System.out.println("黑体");
}
if (e.getSource() == jrb3){
bt.setFont(new Font("宋体",Font.ITALIC, 12));
//System.out.println("斜体");
}
}
public static void main(String[] args) {
Test2 t2 = new Test2();
}
}