资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Java源代码教育题,java程序开发基础答案

java这道题该怎么做

Java参考源代码:

创新互联建站是一家专注于做网站、成都网站设计与策划设计,石鼓网站建设哪家好?创新互联建站做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:石鼓等地区。石鼓做网站价格咨询:18982081108

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class Test10 extends JFrame implements ActionListener {

protected JList lstLeft = null;

protected JList lstRight = null;

protected JButton btnAdd = null;

protected String[] arr = {"新闻", "娱乐", "体育", "教育"};

public Test10() {

super("列表框");

initComponent();

this.setSize(400, 300);

this.setVisible(true);

this.setLayout(new FlowLayout());

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void initComponent() {

lstLeft = new JList(arr);

lstRight = new JList();

btnAdd = new JButton("");

this.add(lstLeft);

this.add(btnAdd);

this.add(lstRight);

lstLeft.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

btnAdd.addActionListener(this);

}

public static void main(String[] args) {

new Test10();

}

@Override

public void actionPerformed(ActionEvent e) {

Object[] items = lstLeft.getSelectedValues();

DefaultListModel model = new DefaultListModel();

lstRight.setModel(model);

model.removeAllElements();

for(Object value : items) {

model.addElement(value);

}

}

}

运行测试:

请点击输入图片描述

这道java题怎么做?

Java源代码:

import java.awt.Color;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class RadioDemo extends JFrame {

public RadioDemo() {

init();

this.setLayout(new FlowLayout());

this.setTitle("XX号XXX");

this.setBounds(100, 200, 250, 140);

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

this.setVisible(true);

}

public void init() {

this.setBackground(Color.red);    //设置窗体的背景颜色为红色

JRadioButton rdoRed = new JRadioButton("红色");    //创建内容为“红色”的单选钮对象rdoRed

JRadioButton rdoYellow = new JRadioButton("黄色");//创建内容为“黄色”的单选钮对象rdoYellow

rdoRed.setBackground(null);    //将红色单选钮的背景颜色设置无背景颜色

rdoYellow.setOpaque(false);    //设置黄色单选钮的不透明属性为false

ButtonGroup group = new ButtonGroup();//创建分组对象

group.add(rdoRed);        //将红色单选钮添加到组对象group中

group.add(rdoYellow);    //将黄色单选钮添加到组对象group中

this.add(rdoRed);        //在窗体中添加红色单选钮

this.add(rdoYellow);    //在窗体中添加黄色单选钮

rdoRed.setSelected(true);    //设置红色单选钮在初始状态下处于选中状态

rdoRed.addActionListener(new ActionListener(){        //给红色单选钮添加事件处理程序

@Override

public void actionPerformed(ActionEvent e) {

getContentPane().setBackground(Color.red);    //设置窗体的背景颜色为红色

}

});

rdoYellow.addActionListener(new ActionListener(){    //给黄色单选钮添加事件处理程序

@Override

public void actionPerformed(ActionEvent e) {

getContentPane().setBackground(Color.yellow);    //设置窗体的背景颜色为黄色

}

});

}

public static void main(String[] args) {

new RadioDemo();

}

}

运行测试:

请教两道JAVA题

第一题: 选D

子类继承父类的所有属性和方法

B为A的子类 用A去实例B 当然可以

C为B的子类 用B去实例C 当然也可以

可以理解????

既然 子类继承父类的所有属性和方法

间接的 C也是A的子类了

故有 A a2=new C();

第二题: 选A

final 为最终的 可以修饰类、属性、方法 故A正确

abstract 为抽象的 可修饰类、方法 但是属性 就不行 故B不正确

定义抽象方法不能有方法体 故C不正确

既然final 为最终的 就不能更改 故D不正确

希望看得懂

Java大一的题目求大神帮忙看看怎么写TAT求源代码

哈哈~网上很多哈,GUI我也不会,现学现卖一个

package swing;

import javafx.embed.swing.JFXPanel;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

/**

* @author wenxy

* @create 2020-05-01

*/

public class JavaFxDate {

public static void main(String[] args) {

// 创建 JFrame 实例

JFrame frame = new JFrame();

// Setting the width and height of frame

frame.setSize(310, 180);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/* 创建面板,这个类似于 HTML 的 div 标签

* 我们可以创建多个面板并在 JFrame 中指定位置

* 面板中我们可以添加文本字段,按钮及其他组件。

*/

JPanel panel = new JPanel();

// 添加面板

frame.add(panel);

/*

* 调用用户定义的方法并添加组件到面板

*/

placeComponents(panel);

// 设置界面可见

frame.setVisible(true);

}

private static void placeComponents(JPanel panel) {

/* 布局部分我们这边不多做介绍

* 这边设置布局为 null

*/

panel.setLayout(null);

// 创建 JLabel

JLabel userLabel = new JLabel("请输入日期字符串");

userLabel.setBounds(5, 5, 300, 25);

panel.add(userLabel);

/*

* 创建文本域用于用户输入

*/

JTextField userText = new JTextField(20);

userText.setBounds(5, 40, 200, 25);

panel.add(userText);

// 创建 JLabel

JLabel showLable = new JLabel();

showLable.setBounds(5, 70, 300, 25);

panel.add(showLable);

// 创建登录按钮

JButton loginButton = new JButton("转换");

loginButton.setBounds(180, 40, 100, 25);

loginButton.addActionListener(new ActionListener() {

DateFormat input = new SimpleDateFormat("yyyy-MM-dd");

DateFormat output = new SimpleDateFormat("yyyy年MM月dd日");

{

input.setLenient(false);    // 设置严格按格式匹配

output.setLenient(false);

}

@Override

public void actionPerformed(ActionEvent actionEvent) {

try {

Date date = convert(userText.getText());

showLable.setText("成功:" + output.format(date));

showLable.setForeground(Color.GREEN);

} catch (WrongDateException e) {

showLable.setText(e.getMessage());

showLable.setForeground(Color.RED);

}

}

private Date convert(String text) throws WrongDateException {

try {

return input.parse(text);

} catch (ParseException e) {

throw new WrongDateException(text);

}

}

});

panel.add(loginButton);

}

static class WrongDateException extends Exception {

WrongDateException(String s) {

super(s + "不是合法的日期字符串");

}

}

}

JAVA试题求助

1.Java是不区分大小写的语言。(错)

2.Java的源代码中定义几个类, 编译结果就生成几个以.class为后缀的字节码文件。(对)

3.Java的字符类型采用的是ASCII编码。(错) ----unicode

4.在进行类的继承时,子类可以拥有与父类相同名字的属性和方法。(错)-------私有的就不行

5.类中不可以没有构造函数,在类的定义时必须定义类的构造函数。(错)------定义类的时候可以不定义构造函数, 自动继承Object的构造函数

6.类的继承机制和接口的实现机制是完全相同的。(错)------继承不必要重新定义一些抽象方法,但是实现接口必须要实现接口里的所有方法

7.在DOS界面中,当从键盘读入数据时,提取到的数据就是数据类型,不需要进行数据类型的转换。(错)--------提取到的数据都以字符串形式表示,根据需要转化成其他基本类型

8.System类不能实例化,即不能创建System类的对象。(对)-------System的构造方法是私有的.

9.Java源程序是由类定义组成的,每个程序可以定义若干个类,但只有一个类是主类。(对)

10.一个类只能有一个父类,但一个接口可以有一个以上的父接口。(对)

11.在Java中,‘a‘与”a”代表的含义是一样的,它们之间没有区别。(错)

12.Java的源代码中无论定义多少个类, 编译结果就只生成一个以.class为后缀的字节码文件。(错)

13.Java的字符类型采用的是Unicode编码,每个Unicode码占16个比特。(对)

14.多维数组中每一维的长度可以不相同。(对)

15.在类中定义重载方法时,每个重载方法的参数个数或参数类型可以相同。(对) --------只要不是个数和类型完全相同.

16.Java源程序是由类定义组成的,每个程序可以定义若干个类,但只有一个类是主类。(对)

17.在进行类的继承时,子类不能拥有与父类相同名字的属性和方法。(错)

18.System类不能实例化,即不能创建System类的对象。(对)

19.一个类只能有一个父类,但一个接口可以有一个以上的父接口。(对)

20.类中不可以没有构造函数,在类的定义时必须定义类的构造函数。(错)


本文标题:Java源代码教育题,java程序开发基础答案
文章网址:http://cdkjz.cn/article/hdechh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220