新聞中心
java這道題該怎么做
Java參考源代碼:
創(chuàng)新互聯(lián)建站是一家專注于做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)與策劃設(shè)計(jì),石鼓網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)10年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:石鼓等地區(qū)。石鼓做網(wǎng)站價(jià)格咨詢: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);
}
}
}
運(yùn)行測試:
請(qǐng)點(diǎn)擊輸入圖片描述
這道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號(hào)XXX");
this.setBounds(100,?200,?250,?140);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
}
public?void?init()?{
this.setBackground(Color.red);????//設(shè)置窗體的背景顏色為紅色
JRadioButton?rdoRed?=?new?JRadioButton("紅色");????//創(chuàng)建內(nèi)容為“紅色”的單選鈕對(duì)象rdoRed
JRadioButton?rdoYellow?=?new?JRadioButton("黃色");//創(chuàng)建內(nèi)容為“黃色”的單選鈕對(duì)象rdoYellow
rdoRed.setBackground(null);????//將紅色單選鈕的背景顏色設(shè)置無背景顏色
rdoYellow.setOpaque(false);????//設(shè)置黃色單選鈕的不透明屬性為false
ButtonGroup?group?=?new?ButtonGroup();//創(chuàng)建分組對(duì)象
group.add(rdoRed);????????//將紅色單選鈕添加到組對(duì)象group中
group.add(rdoYellow);????//將黃色單選鈕添加到組對(duì)象group中
this.add(rdoRed);????????//在窗體中添加紅色單選鈕
this.add(rdoYellow);????//在窗體中添加黃色單選鈕
rdoRed.setSelected(true);????//設(shè)置紅色單選鈕在初始狀態(tài)下處于選中狀態(tài)
rdoRed.addActionListener(new?ActionListener(){????????//給紅色單選鈕添加事件處理程序
@Override
public?void?actionPerformed(ActionEvent?e)?{
getContentPane().setBackground(Color.red);????//設(shè)置窗體的背景顏色為紅色
}
});
rdoYellow.addActionListener(new?ActionListener(){????//給黃色單選鈕添加事件處理程序
@Override
public?void?actionPerformed(ActionEvent?e)?{
getContentPane().setBackground(Color.yellow);????//設(shè)置窗體的背景顏色為黃色
}
});
}
public?static?void?main(String[]?args)?{
new?RadioDemo();
}
}
運(yùn)行測試:
請(qǐng)教兩道JAVA題
第一題: 選D
子類繼承父類的所有屬性和方法
B為A的子類 用A去實(shí)例B 當(dāng)然可以
C為B的子類 用B去實(shí)例C 當(dāng)然也可以
可以理解????
既然 子類繼承父類的所有屬性和方法
間接的 C也是A的子類了
故有 A a2=new C();
第二題: 選A
final 為最終的 可以修飾類、屬性、方法 故A正確
abstract 為抽象的 可修飾類、方法 但是屬性 就不行 故B不正確
定義抽象方法不能有方法體 故C不正確
既然final 為最終的 就不能更改 故D不正確
希望看得懂
Java大一的題目求大神幫忙看看怎么寫TAT求源代碼
哈哈~網(wǎng)上很多哈,GUI我也不會(huì),現(xiàn)學(xué)現(xiàn)賣一個(gè)
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) {
// 創(chuàng)建 JFrame 實(shí)例
JFrame frame = new JFrame();
// Setting the width and height of frame
frame.setSize(310, 180);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/* 創(chuàng)建面板,這個(gè)類似于 HTML 的 div 標(biāo)簽
* 我們可以創(chuàng)建多個(gè)面板并在 JFrame 中指定位置
* 面板中我們可以添加文本字段,按鈕及其他組件。
*/
JPanel panel = new JPanel();
// 添加面板
frame.add(panel);
/*
* 調(diào)用用戶定義的方法并添加組件到面板
*/
placeComponents(panel);
// 設(shè)置界面可見
frame.setVisible(true);
}
private static void placeComponents(JPanel panel) {
/* 布局部分我們這邊不多做介紹
* 這邊設(shè)置布局為 null
*/
panel.setLayout(null);
// 創(chuàng)建 JLabel
JLabel userLabel = new JLabel("請(qǐng)輸入日期字符串");
userLabel.setBounds(5, 5, 300, 25);
panel.add(userLabel);
/*
* 創(chuàng)建文本域用于用戶輸入
*/
JTextField userText = new JTextField(20);
userText.setBounds(5, 40, 200, 25);
panel.add(userText);
// 創(chuàng)建 JLabel
JLabel showLable = new JLabel();
showLable.setBounds(5, 70, 300, 25);
panel.add(showLable);
// 創(chuàng)建登錄按鈕
JButton loginButton = new JButton("轉(zhuǎn)換");
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); ? ?// 設(shè)置嚴(yán)格按格式匹配
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是不區(qū)分大小寫的語言。(錯(cuò))
2.Java的源代碼中定義幾個(gè)類, 編譯結(jié)果就生成幾個(gè)以.class為后綴的字節(jié)碼文件。(對(duì))
3.Java的字符類型采用的是ASCII編碼。(錯(cuò)) ----unicode
4.在進(jìn)行類的繼承時(shí),子類可以擁有與父類相同名字的屬性和方法。(錯(cuò))-------私有的就不行
5.類中不可以沒有構(gòu)造函數(shù),在類的定義時(shí)必須定義類的構(gòu)造函數(shù)。(錯(cuò))------定義類的時(shí)候可以不定義構(gòu)造函數(shù), 自動(dòng)繼承Object的構(gòu)造函數(shù)
6.類的繼承機(jī)制和接口的實(shí)現(xiàn)機(jī)制是完全相同的。(錯(cuò))------繼承不必要重新定義一些抽象方法,但是實(shí)現(xiàn)接口必須要實(shí)現(xiàn)接口里的所有方法
7.在DOS界面中,當(dāng)從鍵盤讀入數(shù)據(jù)時(shí),提取到的數(shù)據(jù)就是數(shù)據(jù)類型,不需要進(jìn)行數(shù)據(jù)類型的轉(zhuǎn)換。(錯(cuò))--------提取到的數(shù)據(jù)都以字符串形式表示,根據(jù)需要轉(zhuǎn)化成其他基本類型
8.System類不能實(shí)例化,即不能創(chuàng)建System類的對(duì)象。(對(duì))-------System的構(gòu)造方法是私有的.
9.Java源程序是由類定義組成的,每個(gè)程序可以定義若干個(gè)類,但只有一個(gè)類是主類。(對(duì))
10.一個(gè)類只能有一個(gè)父類,但一個(gè)接口可以有一個(gè)以上的父接口。(對(duì))
11.在Java中,‘a(chǎn)‘與”a”代表的含義是一樣的,它們之間沒有區(qū)別。(錯(cuò))
12.Java的源代碼中無論定義多少個(gè)類, 編譯結(jié)果就只生成一個(gè)以.class為后綴的字節(jié)碼文件。(錯(cuò))
13.Java的字符類型采用的是Unicode編碼,每個(gè)Unicode碼占16個(gè)比特。(對(duì))
14.多維數(shù)組中每一維的長度可以不相同。(對(duì))
15.在類中定義重載方法時(shí),每個(gè)重載方法的參數(shù)個(gè)數(shù)或參數(shù)類型可以相同。(對(duì)) --------只要不是個(gè)數(shù)和類型完全相同.
16.Java源程序是由類定義組成的,每個(gè)程序可以定義若干個(gè)類,但只有一個(gè)類是主類。(對(duì))
17.在進(jìn)行類的繼承時(shí),子類不能擁有與父類相同名字的屬性和方法。(錯(cuò))
18.System類不能實(shí)例化,即不能創(chuàng)建System類的對(duì)象。(對(duì))
19.一個(gè)類只能有一個(gè)父類,但一個(gè)接口可以有一個(gè)以上的父接口。(對(duì))
20.類中不可以沒有構(gòu)造函數(shù),在類的定義時(shí)必須定義類的構(gòu)造函數(shù)。(錯(cuò))
網(wǎng)站名稱:Java源代碼教育題,java程序開發(fā)基礎(chǔ)答案
標(biāo)題鏈接:http://fisionsoft.com.cn/article/hdechh.html