@Sarah
2015-11-05T17:55:24.000000Z
字数 6261
阅读 914
java笔记
j2ee/andriod(widget)
pc:c++/.net
html特别简单,就是超文本,没有逻辑,不是语言,就像写论文排版格式 用dream weaver
js
GUI:
1awt:原始
2swing:丰富 复杂 慢
1组件component:窗口,按钮,文字 文本框 菜单
2事件监听:
3布局管理器:
frame :容器
panel:
菜单:menubar/ menu /menuitem
windowlistener:7个抽象 7函数实现,windowAdapter实现
List 列表
choice 下拉菜单
checkbox 男女
textArea 文本框 多行
Diolog:容器
import java.awt.*;
import java.awt.event.*;
public class Test implements ActionListener{
Button[] bb;
TextField tf1=new TextField("0",10);
TextField tf2=new TextField("0",10);
public static void main(String[] args) {
new Test().go();//为了后面的this
}
void go(){
Frame f=new Frame("Test Frame");//0*0,unvisible
MenuBar mb=new MenuBar();
f.setMenuBar(mb);
Menu m1=new Menu("Game");
mb.add(m1);
MenuItem mi1=new MenuItem("New game");
MenuItem mi2=new MenuItem("Exit");
m1.add(mi1);
m1.addSeparator();
m1.add(mi2);
f.setSize(300, 400);
//f.setLayout(new GridLayout());
Button b=new Button("click me");
Panel panS=new Panel();
Panel panN=new Panel();
Panel panW=new Panel();
Panel panE=new Panel();
Panel panC=new Panel();
panN.add(new Label(" "));
panW.add(new Label(" "));
panE.add(new Label(" "));
panC.setLayout(new FlowLayout(FlowLayout.CENTER,0,1));
panS.add(new Label("Score:"));
panS.add(tf1);
panS.add(new Label("Time:"));
panS.add(tf2);
bb=new Button[10*10];
for(int i=0;i<10;i++)
for(int j=0;j<10;j++){
bb[i*10+j]=new Button("");
bb[i*10+j].addActionListener(this);
//前面go()是为了这个this
//bb.setSize(20,20);
panC.add(bb[i*10+j]);
}
f.add(panC,BorderLayout.CENTER);
f.add(panN,BorderLayout.NORTH);
f.add(panW,BorderLayout.WEST);
f.add(panE,BorderLayout.EAST);
f.add(panS,BorderLayout.SOUTH);
f.setVisible(true);
f.addWindowListener(new MyWindowListener());
}
@Override
public void actionPerformed(ActionEvent arg0) {
String t=tf1.getText();
System.out.println(t);
Button b=(Button)arg0.getSource();
for(int i=0;i<100;i++)
if(bb[i]==b)
System.out.println(i);
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;//抽象类,需要给抽象函数重写具体函数
public class MyWindowListener extends WindowAdapter {
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
int i=javax.swing.JOptionPane.showConfirmDialog(null, "Are you exit game?","confirm",javax.swing.JOptionPane.YES_NO_OPTION);
if(i==javax.swing.JOptionPane.YES_OPTION)
System.exit(0);
}
}
//WindowAdapter是windowListner的子类,所以这里只需要把需要用到的函数重写然后覆盖即可,而不用整个全都重写。
上次遗留作业完成
package reminder;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class ReminderTest {
BufferedReader kbr;
public ReminderTest() {
this.kbr = new BufferedReader(new InputStreamReader(System.in));
}
// 读取文件到array list
public List txtToList() {
List<String> todoList = new ArrayList<String>();
try {
FileReader fr = new FileReader("日程.txt");
BufferedReader br = new BufferedReader(fr);
while (true) {
String s = br.readLine();
if (s == null)
break;
todoList.add(s);
}
} catch (Exception e) {
e.printStackTrace();
}
return todoList;
}
// 写数组到txt
public void listToTxt(List<String> todoList) {
try {
File f = new File("日程.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
for (int i = 0; i < todoList.size(); i++) {
bw.write(todoList.get(i) + "\n");
}
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 查看
public void check() {
List<String> todoList = txtToList();
for (String s : todoList) {
String ss[] = s.split(";");
System.out.println("name:" + ss[0]);
System.out.println("address:" + ss[1]);
System.out.println("date:" + ss[2]);
System.out.println("time:" + ss[3]);
if (ss.length > 4)
System.out.println("alarm:" + ss[4]);
System.out.println("-----------------------------------");
}
}
public String inputTodo() {
StringBuffer todo = new StringBuffer();
String s = null;
try {
System.out.print("name:");
s = kbr.readLine();
todo.append(s).append(";");
System.out.print("address:");
s = kbr.readLine();
todo.append(s).append(";");
while (true) {
try {
System.out.print("date(yyyy-mm-dd):");
s = kbr.readLine();
String s1 = s.substring(0, 4);
int i = Integer.parseInt(s1);
String s2 = s.substring(5, 7);
int j = Integer.parseInt(s2);
String s3 = s.substring(8, 10);
int k = Integer.parseInt(s3);
System.out.println(i+" "+j+ " "+k);
Date d=new Date(i-1900,j-1,k);
System.out.println(d);
todo.append(s).append(";");
break;
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("date error,please rewrite");
}
}
while (true) {
try {
System.out.print("time(hh:mm):");
s = kbr.readLine();
String s3 = s.substring(0, 2);
int i = Integer.parseInt(s3);
String s4 = s.substring(3, 5);
int j = Integer.parseInt(s4);
Time t=new Time(i,j,0);
todo.append(s);
break;
} catch (Exception e) {
System.out.println("time error,please rewrite");
}
}
System.out.print("need alarm?(y/n)");
s = kbr.readLine();
if (s.equals("y") || s.equalsIgnoreCase("Y")) {
System.out.print("alarm time:");
s = kbr.readLine();
todo.append(";").append(s);
}
} catch (IOException e) {
e.printStackTrace();
}
return todo.toString();
}
// 录入
public void input() {
List<String> todoList = txtToList();
todoList.add(inputTodo());
listToTxt(todoList);
}
// 删除
public void delete() {
System.out.println("plese input the name to delete:");
List<String> todoList = txtToList();
String j = "";
try {
j = kbr.readLine();
for (String s : todoList) {
if (s.startsWith(j)) {
todoList.remove(s);
System.out.println("done.");
break;
}
}
;
listToTxt(todoList);
} catch (IOException e) {
e.printStackTrace();
}
}
// 修改
public void change() {
int k = 0;
List<String> todoList = txtToList();
String x = null;
try {
System.out.println("input the name to change...");
x = kbr.readLine();
for (String s : todoList) {
if (s.startsWith(x)) {
todoList.remove(s);
todoList.add(inputTodo());
System.out.println("done.");
break;
}
}
;
} catch (IOException e) {
e.printStackTrace();
}
listToTxt(todoList);
}
// 设置闹钟
public void alarm() {
String x = new String();
List<String> todoList = txtToList();
try {
System.out.println("set the alarm time HH:mm");
x = kbr.readLine();
} catch (IOException e) {
e.printStackTrace();
}
todoList.set(4, x);
listToTxt(todoList);
}
public static void main(String[] args) {
ReminderTest rm = new ReminderTest();
//new AlarmThread(rm).start();
rm.go();
}
void go() {
while (true) {
System.out.println("1:check todo list");
System.out.println("2:input new todo");
System.out.println("3:delete todo list");
System.out.println("4:change todo list");
System.out.print("0:exit>>>>");
String s = null;
try {
s = kbr.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s.equals("1")) {
check();
} else if (s.equals("2")) {
input();
} else if (s.equals("3")) {
delete();
} else if (s.equals("4")) {
change();
} else if (s.equals("5")) {
alarm();
} else if (s.equals("0")) {
System.exit(0);
}
}
}
}