道java_请问这道java里的这几个语句是什么意思
題目:本程序的功能是列表的選擇,并將選中的內容顯示在文本區域中。窗口中有一個文本區域和一個支持多項選擇的列表,當選中列表中的一項或多項時,文本區域中就會分行顯示所選項的索...
題目:本程序的功能是列表的選擇,并將選中的內容顯示在文本區域中。窗口中有一個文本區域和一個支持多項選擇的列表,當選中列表中的一項或多項時,文本區域中就會分行顯示所選項的索引值和值。如圖所示。
我想問的句子加上了【】
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class exam_37
{
public static void main(String[] args)
{
ListFrame frame = new ListFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class ListFrame extends JFrame
{
public ListFrame()
{
setTitle("exam_37");
setSize(WIDTH, HEIGHT);
Container contentPane = getContentPane();
JPanel textPanel = new JPanel();
myTextArea = 【new JTextArea(checkedLabel, 5, 20);】
【JScrollPane textScrollPane = new JScrollPane(myTextArea);】
textPanel.add(textScrollPane);
contentPane.add(textPanel);
listPanel = new JPanel();
【String[] courses = {"數學", "英語", "物理", "化學",
"生物", "地理"};】
courseList = new JList(courses);
【courseList.setVisibleRowCount(4);】
【courseList.addListSelectionListener(new courseListener());】
JScrollPane listScrollPane = new JScrollPane(courseList);
listPanel.add(listScrollPane);
【contentPane.add(listPanel, BorderLayout.SOUTH);】
}
private class courseListener implements ListSelectionListener
{
public void valueChanged(ListSelectionEvent event)
{
Object[] selectedCourses = 【courseList.getSelectedValues();】
int[] selectedIndexCourses = courseList.getSelectedIndices();
【StringBuffer tempSeletedText = new StringBuffer(checkedLabel);】
for (int i = 0; i
{
String str1 = new String(selectedIndexCourses[i] + ", ");
String str2 = (String)selectedCourses[i];
【tempSeletedText.append(str1);】
tempSeletedText.append(str2);
tempSeletedText.append("\n");
}
myTextArea.setText(【 tempSeletedText.toString()】);
}
}
public static final int WIDTH = 300;
public static final int HEIGHT = 250;
public static final String checkedLabel="請選擇你喜歡的課程:\n";
private JTextArea myTextArea;
private JList courseList;
private JPanel listPanel;
}
展開
總結
以上是生活随笔為你收集整理的道java_请问这道java里的这几个语句是什么意思的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java输入一个数字输出_java 输入
- 下一篇: 联想拯救者r720适合java么_联想拯