扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
我给你如下:/*
创新互联是一家朝气蓬勃的网站建设公司。公司专注于为企业提供信息化建设解决方案。从事网站开发,网站制作,网站设计,网站模板,微信公众号开发,软件开发,微信平台小程序开发,十年建站对成都展览展示等多个领域,拥有多年设计经验。
* WriteBoard.java
*
* Created on 2006年12月19日, 下午7:26
*/
/**
*
* @author LecH.giF
*/
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.awt.FileDialog;
public class WriteBoard extends java.awt.Frame {
Clipboard clipboard =null;
FileDialog fc = new FileDialog(this);
/** Creates new form WriteBoard */
public WriteBoard() {
clipboard = getToolkit().getSystemClipboard();
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// editor-fold defaultstate="collapsed" desc=" Generated Code "
private void initComponents() {
textArea1 = new java.awt.TextArea();
menuBar1 = new java.awt.MenuBar();
menu1 = new java.awt.Menu();
menuItem1 = new java.awt.MenuItem();
menuItem2 = new java.awt.MenuItem();
menuItem3 = new java.awt.MenuItem();
menuItem4 = new java.awt.MenuItem();
menuItem5 = new java.awt.MenuItem();
menu2 = new java.awt.Menu();
menuItem6 = new java.awt.MenuItem();
menuItem7 = new java.awt.MenuItem();
menuItem8 = new java.awt.MenuItem();
setTitle("WriteBoard");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
add(textArea1, java.awt.BorderLayout.CENTER);
menu1.setLabel("Menu");
menuItem1.setLabel("\u65b0\u5efa");
menuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
newText(evt);
}
});
menu1.add(menuItem1);
menuItem2.setLabel("\u6253\u5f00");
menuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
open(evt);
}
});
menu1.add(menuItem2);
menuItem3.setLabel("\u4fdd\u5b58");
menuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem3ActionPerformed(evt);
}
});
menu1.add(menuItem3);
menuItem4.setLabel("\u53e6\u5b58\u4e3a");
menuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem4ActionPerformed(evt);
}
});
menu1.add(menuItem4);
menuItem5.setLabel("\u9000\u51fa");
menuItem5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exit(evt);
}
});
menu1.add(menuItem5);
menuBar1.add(menu1);
menu2.setLabel("\u7f16\u8f91");
menuItem6.setLabel("\u526a\u5207");
menuItem6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem6ActionPerformed(evt);
}
});
menu2.add(menuItem6);
menuItem7.setLabel("\u590d\u5236");
menuItem7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem7ActionPerformed(evt);
}
});
menu2.add(menuItem7);
menuItem8.setLabel("\u7c98\u8d34");
menuItem8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
menuItem8ActionPerformed(evt);
}
});
menu2.add(menuItem8);
menuBar1.add(menu2);
setMenuBar(menuBar1);
pack();
}// /editor-fold
private void menuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
fc.show();
if(fc.getFile()!=null){
File file = new File(fc.getFile());
try {
PrintWriter pw = new PrintWriter(file);
pw.print(textArea1.getText());
pw.flush();
pw.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
else{
return;
}
}
private void menuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
fc.show();
if(fc.getFile()!=null){
File file = new File(fc.getFile());
try {
PrintWriter pw = new PrintWriter(file);
pw.print(textArea1.getText());
pw.flush();
pw.close();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
else{
return;
}
}
private void menuItem8ActionPerformed(java.awt.event.ActionEvent evt) {
Transferable contents = clipboard.getContents(this);
DataFlavor flavor = DataFlavor.stringFlavor;
if(contents.isDataFlavorSupported(flavor))
try{
String str;
str=(String)contents.getTransferData(flavor);
textArea1.append(str);
}catch(Exception e){}
}
private void menuItem7ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = this.textArea1.getSelectedText();
StringSelection text = new StringSelection(temp);
clipboard.setContents(text,null);
}
private void menuItem6ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = this.textArea1.getSelectedText();
StringSelection text = new StringSelection(temp);
clipboard.setContents(text,null);
int start = textArea1.getSelectionStart();
int end = textArea1.getSelectionEnd();
textArea1.replaceRange("",start,end);
}
private void open(java.awt.event.ActionEvent evt) {
fc.show();
if(fc.getFile()!=null){
File file = new File(fc.getFile());
try {
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String s;
try {
while((s= br.readLine())!=null){
textArea1.append(s+"\n");
}
fr.close();
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
else{
return;
}
}
private void newText(java.awt.event.ActionEvent evt) {
this.textArea1.setText("");
}
private void exit(java.awt.event.ActionEvent evt) {
System.exit(0);
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new WriteBoard().setVisible(true);
}
});
}
// Variables declaration - do not modify
private java.awt.Menu menu1;
private java.awt.Menu menu2;
private java.awt.MenuBar menuBar1;
private java.awt.MenuItem menuItem1;
private java.awt.MenuItem menuItem2;
private java.awt.MenuItem menuItem3;
private java.awt.MenuItem menuItem4;
private java.awt.MenuItem menuItem5;
private java.awt.MenuItem menuItem6;
private java.awt.MenuItem menuItem7;
private java.awt.MenuItem menuItem8;
private java.awt.TextArea textArea1;
// End of variables declaration
}
如果你用开发工具,比如eclipse,那么鼠标滑过代码时,会有一个层显示出来,是一些对代码的介绍.
如果是系统定义的类型,你按住ctrl
点击这厅纳个文字,会跳派差到
所谓源代码(source
code)了.
而默认,鼠标滑过,按下shift,
也会有源代码提示的.
前提是你设置好了source
code
的路径扮羡没.
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class GradeStatistic {
public static void main(String[] args) {
GradeStatistic gs = new GradeStatistic();
ListMark list = new ArrayListMark();
float sum = 0;
while(true){
Scanner sc = new Scanner(System.in);
System.out.print("Please input student name: ");
String name = sc.nextLine();
if(name.equals("备差end")){
break;
}
System.out.print("Please input student score: ");
float score = sc.nextFloat();
sum += score;
list.add(gs.new Mark(name, score));
}
float max = list.get(0).getScore();
float min = list.get(0).getScore();
for(Mark mark: list){
if(max mark.getScore()){
max = mark.getScore();
}
if(min mark.getScore()){
min = mark.getScore();
}
}
float average = sum / list.size();
System.out.println("好瞎Average is: " + average);
System.out.println("Max is: " + max);
System.out.println("Min is: "仿袜皮 + min);
}
private class Mark{
private String name;
private float score;
public Mark(String name, float score){
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public float getScore() {
return score;
}
}
}
----------------------
Please input student name: Zhang san
Please input student score: 100
Please input student name: Li Si
Please input student score: 91
Please input student name: Ec
Please input student score: 35
Please input student name: ma qi
Please input student score: 67
Please input student name: end
Average is: 73.25
Max is: 100.0
Min is: 35.0
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流