当前位置:首页 > 代码 > 正文

java记事本代码(java记事本代码换行)

admin 发布:2022-12-19 16:57 140


今天给各位分享java记事本代码的知识,其中也会对java记事本代码换行进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

记事本上的JAVA代码如何在DOS里面运行

将你的记事本文件保存成Java文件,进入dos,进入到你的记事本的所在目录,执行javac命令(例如文件名为Hello.Java,输入javac

Hello.java,按回车),如果编译通过,再执行Java命令(Java

Hello)

java简单记事本源代码 带解释

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

class test implements ActionListener

{

JFrame frame;

JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21,b22,b23,b24,b25,b26,b27,b28,b29,b30,b31;

JTextArea ta;

JPanel p1,p2,p3,p4;

JMenuBar mb;

JMenu m1,m2,m3;

JMenuItem mt1,mt2,mt3,mt4,mt5,mt6,mt7;

JRadioButton rb1,rb2;

ButtonGroup bg;

Double d1=0.0,d2=0.0,d3=0.0,d4=1.0,d5=1.0;

String s1="",s2="",s3="",s4="";

int a=0;

char c1;

int i=0;

public static void main(String[] args)

{

test that=new test();

that.go();

}

public void go()

{

frame=new JFrame("计算器");

Container cp= frame.getContentPane();

cp.setLayout(new FlowLayout());

b1=new JButton("7");b2=new JButton("8");b3=new JButton("9");b4=new JButton("/");b5=new JButton("1/x");b6=new JButton("sin");b7=new JButton("log");

b8=new JButton("4");b9=new JButton("5");b10=new JButton("6");b11=new JButton("*");b12=new JButton("x^y");b13=new JButton("cos");b14=new JButton("ln");

b15=new JButton("1");b16=new JButton("2");b17=new JButton("3");b18=new JButton("-");b19=new JButton(new ImageIcon("lanying.gif"));b20=new JButton("tan");b21=new JButton("x^3");

b22=new JButton("0");b23=new JButton("+/-");b24=new JButton(".");b25=new JButton("+");b26=new JButton("√x");b27=new JButton("cot");b28=new JButton("x^2");

b29=new JButton("Backspace");b30=new JButton("C");b31=new JButton("=");

mb=new JMenuBar();

m1=new JMenu("文件(F)");m2=new JMenu("编辑(E)");m3=new JMenu("帮助(H)");

mt1=new JMenuItem("清零");mt2=new JMenuItem("退出");mt3=new JMenuItem("复制");mt4=new JMenuItem("粘贴");mt5=new JMenuItem("版本");mt6=new JMenuItem("标准型");mt7=new JMenuItem("科学型");

ta=new JTextArea(1,30);

p1=new JPanel();p2=new JPanel();p3=new JPanel();p4=new JPanel();

rb1=new JRadioButton("科学型");rb2=new JRadioButton("标准型");

bg=new ButtonGroup();

b1.setForeground(Color.blue);b1.setBackground(Color.white);b2.setForeground(Color.blue);b2.setBackground(Color.white);

b3.setForeground(Color.blue);b3.setBackground(Color.white);b8.setForeground(Color.blue);b8.setBackground(Color.white);

b9.setForeground(Color.blue);b9.setBackground(Color.white);b10.setForeground(Color.blue);b10.setBackground(Color.white);

b15.setForeground(Color.blue);b15.setBackground(Color.white);b16.setForeground(Color.blue);b16.setBackground(Color.white);

b17.setForeground(Color.blue);b17.setBackground(Color.white);b22.setForeground(Color.blue);b22.setBackground(Color.white);

b23.setForeground(Color.blue);b23.setBackground(Color.white);b24.setForeground(Color.blue);b24.setBackground(Color.white);

b4.setForeground(Color.red);b4.setBackground(Color.white);b11.setForeground(Color.red);b11.setBackground(Color.white);

b18.setForeground(Color.red);b18.setBackground(Color.white);b25.setForeground(Color.red);b25.setBackground(Color.white);

b5.setForeground(Color.blue);b5.setBackground(Color.white);b6.setForeground(Color.blue);b6.setBackground(Color.white);

b7.setForeground(Color.blue);b7.setBackground(Color.white);b12.setForeground(Color.blue);b12.setBackground(Color.white);

b13.setForeground(Color.blue);b13.setBackground(Color.white);b14.setForeground(Color.blue);b14.setBackground(Color.white);

b19.setForeground(Color.blue);b19.setBackground(Color.white);b20.setForeground(Color.blue);b20.setBackground(Color.white);

b21.setForeground(Color.blue);b21.setBackground(Color.white);b26.setForeground(Color.blue);b26.setBackground(Color.white);

b27.setForeground(Color.blue);b27.setBackground(Color.white);b28.setForeground(Color.blue);b28.setBackground(Color.white);

b29.setForeground(Color.red);b29.setBackground(Color.white);b30.setForeground(Color.red);b30.setBackground(Color.white);

b31.setForeground(Color.red);b31.setBackground(Color.white);

bg.add(rb1);bg.add(rb2);

p1.setBackground(Color.yellow);

cp.setBackground(Color.CYAN);

m1.setMnemonic(KeyEvent.VK_F);m2.setMnemonic(KeyEvent.VK_E);m3.setMnemonic(KeyEvent.VK_H);

m1.add(mt6);m1.add(mt7);m1.addSeparator();m1.add(mt1);m1.addSeparator();m1.add(mt2);m2.add(mt3);m2.addSeparator();m2.add(mt4);m3.add(mt5);

mb.add(m1);mb.add(m2);mb.add(m3);

frame.setJMenuBar(mb);

p2.setLayout(new GridLayout(4,7));

p3.setLayout(new GridLayout(1,3));

ta.setEditable(false);

p1.add(ta);

p2.add(b1);p2.add(b2);p2.add(b3);p2.add(b4);p2.add(b5);p2.add(b6);p2.add(b7);

p2.add(b8);p2.add(b9);p2.add(b10);p2.add(b11);p2.add(b12);p2.add(b13);p2.add(b14);

p2.add(b15);p2.add(b16);p2.add(b17);p2.add(b18);p2.add(b19);p2.add(b20);p2.add(b21);

p2.add(b22);p2.add(b23);p2.add(b24);p2.add(b25);p2.add(b26);p2.add(b27);p2.add(b28);

p3.add(b29);p3.add(b30);p3.add(b31);

Border etched=BorderFactory.createEtchedBorder();

Border border=BorderFactory.createTitledBorder(etched,"计算类型");

p4.add(rb1);p4.add(rb2);

p4.setBorder(border);

b2.setActionCommand("8");

b2.addActionListener(this);

cp.add(p1);cp.add(p4);cp.add(p2);cp.add(p3);

frame.setSize(400,330);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

b1.setActionCommand("7");

b1.addActionListener(this);

b2.setActionCommand("8");

b2.addActionListener(this);

b3.setActionCommand("9");

b3.addActionListener(this);

b4.setActionCommand("/");

b4.addActionListener(this);

b5.setActionCommand("1/x");

b5.addActionListener(this);

b6.setActionCommand("sin");

b6.addActionListener(this);

b7.setActionCommand("log");

b7.addActionListener(this);

b8.setActionCommand("4");

b8.addActionListener(this);

b9.setActionCommand("5");

b9.addActionListener(this);

b10.setActionCommand("6");

b10.addActionListener(this);

b11.setActionCommand("*");

b11.addActionListener(this);

b12.setActionCommand("x^y");

b12.addActionListener(this);

b13.setActionCommand("cos");

b13.addActionListener(this);

b14.setActionCommand("ln");

b14.addActionListener(this);

b15.setActionCommand("1");

b15.addActionListener(this);

b16.setActionCommand("2");

b16.addActionListener(this);

b17.setActionCommand("3");

b17.addActionListener(this);

b18.setActionCommand("-");

b18.addActionListener(this);

b19.setActionCommand("x!");

b19.addActionListener(this);

b20.setActionCommand("tan");

b20.addActionListener(this);

b21.setActionCommand("x^3");

b21.addActionListener(this);

b22.setActionCommand("0");

b22.addActionListener(this);

b23.setActionCommand("+/-");

b23.addActionListener(this);

b24.setActionCommand(".");

b24.addActionListener(this);

b25.setActionCommand("+");

b25.addActionListener(this);

b26.setActionCommand("√x");

b26.addActionListener(this);

b27.setActionCommand("cot");

b27.addActionListener(this);

b28.setActionCommand("x^2");

b28.addActionListener(this);

b29.setActionCommand("Backspace");

b29.addActionListener(this);

b30.setActionCommand("C");

b30.addActionListener(this);

b31.setActionCommand("=");

b31.addActionListener(this);

rb1.setActionCommand("kxx");

rb1.addActionListener(this);

rb2.setActionCommand("bzx");

rb2.addActionListener(this);

}

public void actionPerformed(ActionEvent e) //throws Exception

{

if (e.getActionCommand()=="bzx")

{

b5.setEnabled(false);b6.setEnabled(false);b7.setEnabled(false);

b12.setEnabled(false);b13.setEnabled(false);b14.setEnabled(false);

b19.setEnabled(false);b20.setEnabled(false);b21.setEnabled(false);

b26.setEnabled(false);b27.setEnabled(false);b28.setEnabled(false);

}

if (e.getActionCommand()=="kxx")

{

b5.setEnabled(true);b6.setEnabled(true);b7.setEnabled(true);

b12.setEnabled(true);b13.setEnabled(true);b14.setEnabled(true);

b19.setEnabled(true);b20.setEnabled(true);b21.setEnabled(true);

b26.setEnabled(true);b27.setEnabled(true);b28.setEnabled(true);

}

if (e.getActionCommand()=="1")

{

ta.append("1");

}

if (e.getActionCommand()=="2")

{

ta.append("2");

}

if (e.getActionCommand()=="3")

{

ta.append("3");

}

if (e.getActionCommand()=="4")

{

ta.append("4");

}

if (e.getActionCommand()=="5")

{

ta.append("5");

}

if (e.getActionCommand()=="6")

{

ta.append("6");

}

if (e.getActionCommand()=="7")

{

ta.append("7");

}

if (e.getActionCommand()=="8")

{

ta.append("8");

}

if (e.getActionCommand()=="9")

{

ta.append("9");

}

if (e.getActionCommand()=="0")

{

ta.append("0");

}

if (e.getActionCommand()=="+")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=1;

}

if (e.getActionCommand()=="-")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=2;

}

if (e.getActionCommand()=="*")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=3;

}

if (e.getActionCommand()=="/")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=4;

}

if (e.getActionCommand()=="=")

{

s2=ta.getText();

d2=Double.parseDouble(s2);

if(i==1)

{

d3=d1+d2;

ta.setText( d3.toString());

}

if(i==2)

{

d3=d1-d2;

ta.setText( d3.toString());

}

if(i==3)

{

d3=d1*d2;

ta.setText( d3.toString());

}

if(i==4)

{

if(d2==0.0)

ta.setText("ERROR");

else

{

d3=d1/d2;

ta.setText( d3.toString());

}

}

if (i==5)

{

s2=ta.getText();

d2 = Double.parseDouble(s2);

for (int l=1;l=d2 ; l++)

{

d5=d5*d1;

}

ta.setText( d5.toString());

}

}

if (e.getActionCommand()=="C")

{

ta.setText("");

d4=1.0;

d5=1.0;

}

/*if (e.getActionCommand()=="Backspace")

{

s3=ta.getText();

a=s3.length();

//ta.cut(ta.select(a-1,a));

s4=ta.getText(1,3);

ta.setText(s4);

}

*/

if (e.getActionCommand()=="1/x")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=1/d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()==".")

{

ta.append(".");

}

if (e.getActionCommand()=="+/-")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=0-d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^2")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=d1*d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^3")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=d1*d1*d1;

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x^y")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

ta.setText("");

i=5;

// d2=d1*d1*d1;

// ta.setText( d2.toString());

}

if (e.getActionCommand()=="√x")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=Math.sqrt(d1);

ta.setText( d2.toString());

}

if (e.getActionCommand()=="x!")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

if (d10)

{

ta.setText( "error");

}

else if (d1==0)

{

ta.setText( "0.0");

}

else {

for (int k=1;k=d1 ;k++ )

d4=d4*k;

ta.setText( d4.toString());

}

}

if (e.getActionCommand()=="sin")

{

s1=ta.getText();

d1 = Double.parseDouble(s1);

d2=Math.sin(3.1415926*d1/180);

ta.setText( d2.toString());

}

}

}

如何用JAVA编写简单的记事本程序?

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

import java.io.*;

import java.awt.datatransfer.*;public class NewEdit

{

public static void main(String args[])

{

MyFrame EditFrame=new MyFrame();

EditFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

EditFrame.setVisible(true);

}

}class MyFrame extends JFrame

{

public MyFrame()

{ Dimension screenSize=toolKit.getScreenSize();

int screenHeight=screenSize.height;

int screenWidth=screenSize.width;

setSize(screenWidth/2,screenHeight/2);

setLocation(screenWidth/4,screenHeight/4);

Image img=toolKit.getImage("icon.gif");

setIconImage(img);

setTitle("MyEdit");

JMenuBar menuBar=new JMenuBar();

setJMenuBar(menuBar);

JMenu fileMenu=new JMenu("文件");

JMenu editMenu=new JMenu("编辑");

JMenu helpMenu=new JMenu("帮助");

menuBar.add(fileMenu);

menuBar.add(editMenu);

menuBar.add(helpMenu);

JMenuItem newItem=new JMenuItem("新建");

newItem.addActionListener(new NewListener());

JMenuItem openItem=new JMenuItem("打开");

openItem.addActionListener(new OpenListener());

JMenuItem saveItem=new JMenuItem("保存");

saveItem.addActionListener(new SaveListener());

JMenuItem escItem=new JMenuItem("退出");

escItem.addActionListener(new

ActionListener()

{

public void actionPerformed(ActionEvent myE)

{

System.exit(0);

}

});

fileMenu.add(newItem);

fileMenu.add(openItem);

fileMenu.add(saveItem);

fileMenu.add(escItem);

JMenuItem allItem=new JMenuItem("全选");

//JMenuItem copyItem=new JMenuItem("复制");

//CopyAction copyAction=new CopyAction();

//copyItem.addActionListener(copyAction);

JMenuItem cutItem=new JMenuItem("剪切");

//JMenuItem pasteItem=new JMenuItem("粘贴");

//Action pasteAction=new PasteAction();

//pasteItem.addActionListener(pasteAction);

editMenu.add(allItem);

allItem.addActionListener(new

ActionListener()

{

public void actionPerformed(ActionEvent myE)

{

textArea.selectAll();

}

});

CopyAction copyAction=new CopyAction("剪切");

editMenu.add(copyAction);

CutAction cutAction=new CutAction("复制");

editMenu.add(cutAction);

Action pasteAction=new PasteAction("粘贴");

editMenu.add(pasteAction);

popup=new JPopupMenu();

popup.add(copyAction);

popup.add(pasteAction);

popup.add(cutAction);

textArea = new JTextArea();

textArea.add(popup);

textArea.addMouseListener(new

MouseListener(){

public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {

if (e.getButton() == MouseEvent.BUTTON3)

{

popup.show(textArea, e.getX(), e.getY());

}

} public void mouseReleased(MouseEvent e) {} });//可尝试用MouseAdapter,代码可能更简单

JScrollPane scroller = new JScrollPane(textArea);

add(scroller);

//OR--this.getContentPane().add(scroller)

//scroller.setComponentPopupMenu(popup);

//textArea.setInheritsPopupMenu(true);

//scroller.addMouseListener(new MouseAdapter(){});

}

public void writeFile(String fileName)

{

try

{

File file = new File(fileName);

FileWriter write = new FileWriter(file);

write.write(textArea.getText());

write.close();

}

catch(Exception e){

System.out.println("Error closing file!");

}

}

public void openFile(String fileName)

{

try

{

File file = new File(fileName);

FileReader readIn = new FileReader(file);

int size = (int)file.length();

int charsRead = 0;

char[] content = new char[size];

while(readIn.ready())

charsRead += readIn.read(content,charsRead,size-charsRead);

readIn.close();

textArea.setText(new String(content,0,charsRead));

}

catch(IOException e)

{

System.out.println("Error opening file!");

}

}

private class NewListener implements ActionListener

{

public void actionPerformed(ActionEvent myE)

{

textArea.setText("");

}

}

private class OpenListener implements ActionListener

{

public void actionPerformed(ActionEvent myE)

{

openFileDialog.setVisible(true);

fileName = openFileDialog.getDirectory()+openFileDialog.getFile();

if(fileName != null)

{

openFile(fileName);

}

}

}

private class SaveListener implements ActionListener

{

public void actionPerformed(ActionEvent myE)

{

saveFileDialog.setVisible(true);

fileName = saveFileDialog.getDirectory()+saveFileDialog.getFile();

if(fileName !=null)

{

writeFile(fileName);

}

}

}

private class CutAction extends AbstractAction

{

public CutAction(String name)

{

super(name);

}

public void actionPerformed(ActionEvent event)

{

String text = textArea.getSelectedText();

StringSelection selection = new StringSelection(text);

clipboard.setContents(selection,null);

textArea.replaceRange("",textArea.getSelectionStart(),

textArea.getSelectionEnd());

}

}

private class CopyAction extends AbstractAction

{

public CopyAction(String name)

{

super(name);

}

public void actionPerformed(ActionEvent event)

{

String text = textArea.getSelectedText();

StringSelection selection= new StringSelection(text);

clipboard.setContents(selection,null);

}

}

private class PasteAction extends AbstractAction

{

public PasteAction(String name)

{

super(name);

}

public void actionPerformed(ActionEvent event)

{

Transferable contents = clipboard.getContents(this);

if(contents==null)

return;

String text;

text="";

try

{

text = (String)contents.getTransferData(DataFlavor.stringFlavor);

}

catch(Exception ex){}

textArea.replaceRange(text,

textArea.getSelectionStart(),textArea.getSelectionEnd());

}

}

private JTextArea textArea;

private JPopupMenu popup;

private String fileName="";

private FileDialog openFileDialog=new FileDialog(this,"OpenFile",FileDialog.LOAD); private FileDialog saveFileDialog=new FileDialog(this,"SaveFile",FileDialog.SAVE);

Toolkit toolKit = Toolkit.getDefaultToolkit();

private Clipboard clipboard = toolKit.getSystemClipboard();}

用java写的日历记事本代码?

详细代码

//CalendarWindow类:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import java.io.*;

public class CalendarWindow extends JFrame implements ActionListener,

MouseListener,FocusListener{

int year,month,day;

CalendarMessage calendarMessage;

CalendarPad calendarPad;

NotePad notePad;

JTextField showYear,showMonth;

JTextField [] showDay;

CalendarImage calendarImage;

Clock clock;

JButton nextYear,previousYear,nextMonth,previousMonth;

JButton saveDailyRecord,deleteDailyRecord,readDailyRecord;

File dir;

Color backColor=Color.gray;

public CalendarWindow(){

dir=new File("./dailyRecord");

dir.mkdir();

showDay=new JTextField[42];

for(int i=0;ishowDay.length;i++){

showDay[i]=new JTextField();

showDay[i].setBackground(backColor);

showDay[i].setLayout(new GridLayout(3,3));

showDay[i].addMouseListener(this);

showDay[i].addFocusListener(this);

}

calendarMessage=new CalendarMessage();

calendarPad=new CalendarPad();

notePad=new NotePad();

Calendar calendar=Calendar.getInstance();

calendar.setTime(new Date());

year=calendar.get(Calendar.YEAR);

month=calendar.get(Calendar.MONTH)+1;

day=calendar.get(Calendar.DAY_OF_MONTH);

calendarMessage.setYear(year);

calendarMessage.setMonth(month);

calendarMessage.setDay(day);

calendarPad.setCalendarMessage(calendarMessage);

calendarPad.setShowDayTextField(showDay);

notePad.setShowMessage(year,month,day);

calendarPad.showMonthCalendar();

doMark(); //给有日志的号码做标记,见后面的doMark()方法

calendarImage=new CalendarImage();

calendarImage.setImageFile(new File("sea.jpg"));

clock=new Clock();

JSplitPane splitV1=

new JSplitPane(JSplitPane.VERTICAL_SPLIT,calendarPad,calendarImage);

JSplitPane splitV2=

new JSplitPane(JSplitPane.VERTICAL_SPLIT,notePad,clock);

JSplitPane splitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,splitV1,splitV2);

add(splitH,BorderLayout.CENTER);

showYear=new JTextField(""+year,6);

showYear.setFont(new Font("TimesRoman",Font.BOLD,12));

showYear.setHorizontalAlignment(JTextField.CENTER);

showMonth=new JTextField(" "+month,4);

showMonth.setFont(new Font("TimesRoman",Font.BOLD,12));

showMonth.setHorizontalAlignment(JTextField.CENTER);

nextYear=new JButton("下年");

previousYear=new JButton("上年");

nextMonth=new JButton("下月");

previousMonth=new JButton("上月");

nextYear.addActionListener(this);

previousYear.addActionListener(this);

nextMonth.addActionListener(this);

previousMonth.addActionListener(this);

showYear.addActionListener(this);

JPanel north=new JPanel();

north.add(previousYear);

north.add(showYear);

north.add(nextYear);

north.add(previousMonth);

north.add(showMonth);

north.add(nextMonth);

add(north,BorderLayout.NORTH);

saveDailyRecord=new JButton("保存日志") ;

deleteDailyRecord=new JButton("删除日志");

readDailyRecord=new JButton("读取日志");

saveDailyRecord.addActionListener(this);

deleteDailyRecord.addActionListener(this);

readDailyRecord.addActionListener(this);

JPanel pSouth=new JPanel();

pSouth.add(saveDailyRecord);

pSouth.add(deleteDailyRecord);

pSouth.add(readDailyRecord);

add(pSouth,BorderLayout.SOUTH);

setVisible(true);//根据参数 b 的值显示或隐藏此 Window

setBounds(60,60,660,480);

validate();//验证此容器及其所有子组件

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置用户在此窗体上发起 "close" 时默认执行的操作

}

public void actionPerformed(ActionEvent e){

if(e.getSource()==nextYear){

year++;

showYear.setText(""+year);

calendarMessage.setYear(year);

calendarPad.setCalendarMessage(calendarMessage);

calendarPad.showMonthCalendar();

notePad.setShowMessage(year,month,day);

doMark();

}

else if(e.getSource()==previousYear){

year--;

showYear.setText(""+year);

calendarMessage.setYear(year);

calendarPad.setCalendarMessage(calendarMessage);

calendarPad.showMonthCalendar();

notePad.setShowMessage(year,month,day);

doMark();

}

else if(e.getSource()==nextMonth){

month++;

if(month12) month=1;

showMonth.setText(" "+month);

calendarMessage.setMonth(month);

calendarPad.setCalendarMessage(calendarMessage);

calendarPad.showMonthCalendar();

notePad.setShowMessage(year,month,day);

doMark();

}

else if(e.getSource()==previousMonth){

month--;

if(month1) month=12;

showMonth.setText(" "+month);

calendarMessage.setMonth(month);

calendarPad.setCalendarMessage(calendarMessage);

calendarPad.showMonthCalendar();

notePad.setShowMessage(year,month,day);

doMark();

}

else if(e.getSource()==showYear){

String s=showYear.getText().trim();

char a[]=s.toCharArray();

boolean boo=false;

for(int i=0;ia.length;i++)

if(!(Character.isDigit(a[i])))

boo=true;

if(boo==true) //弹出“警告”消息对话框

JOptionPane.showMessageDialog(this,"您输入了非法年份","警告", JOptionPane.WARNING_MESSAGE);

else if(boo==false)

year=Integer.parseInt(s);

showYear.setText(""+year);

calendarMessage.setYear(year);

calendarPad.setCalendarMessage(calendarMessage);

calendarPad.showMonthCalendar();

notePad.setShowMessage(year,month,day);

doMark();

}

else if(e.getSource()==saveDailyRecord){

notePad.save(dir,year,month,day);

doMark();

}

else if(e.getSource()==deleteDailyRecord){

notePad.delete(dir,year,month,day);

doMark();

}

else if(e.getSource()==readDailyRecord)

notePad.read(dir,year,month,day);

}

public void mousePressed(MouseEvent e){

JTextField text=(JTextField)e.getSource();

String str=text.getText().trim();

try{ day=Integer.parseInt(str);

}

catch(NumberFormatException exp){

}

calendarMessage.setDay(day);

notePad.setShowMessage(year,month,day);

}

public void mouseReleased(MouseEvent e){}

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mouseClicked(MouseEvent e) {}

public void focusGained(FocusEvent e){

Component com=(Component)e.getSource();

com.setBackground(Color.red);

}

public void focusLost(FocusEvent e){

Component com=(Component)e.getSource();

com.setBackground(backColor);

}

public void doMark(){

for(int i=0;ishowDay.length;i++){

showDay[i].removeAll();

String str=showDay[i].getText().trim();

try{

int n=Integer.parseInt(str);

if(isHaveDailyRecord(n)==true){ //见后面的isHaveDailyRecord()方法

JLabel mess=new JLabel("存");

mess.setFont(new Font("TimesRoman",Font.PLAIN,11));

mess.setForeground(Color.black) ;

showDay[i].add(mess);

} }

catch(Exception exp){}

}

calendarPad.repaint();

calendarPad.validate();

}

public boolean isHaveDailyRecord(int n){

String key=""+year+""+month+""+n;

String [] dayFile=dir.list();

boolean boo=false;

for(int k=0;kdayFile.length;k++){

if(dayFile[k].equals(key+".txt")){

boo=true;

break;

} }

return boo;

}

public static void main(String args[]){

new CalendarWindow();

}

}

//CalendarPad类:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.*;

public class CalendarPad extends JPanel{

int year,month,day;

CalendarMessage calendarMessage;

JTextField [] showDay;

JLabel title[];

String [] 星期={"SUN/日","MON/一","TUE/二","WED/三","THU/四","FRI/五","SAT/六"};

JPanel north,center;

public CalendarPad(){

setLayout(new BorderLayout());

north=new JPanel();

north.setLayout(new GridLayout(1,7));

center=new JPanel();

center.setLayout(new GridLayout(6,7));

add(center,BorderLayout.CENTER);

add(north,BorderLayout.NORTH);

title=new JLabel[7];

for(int j=0;j7;j++){

title[j]=new JLabel();

title[j].setFont(new Font("TimesRoman",Font.BOLD,12));

title[j].setText(星期[j]);

title[j].setHorizontalAlignment(JLabel.CENTER);

title[j].setBorder(BorderFactory.createRaisedBevelBorder());

north.add(title[j]);

}

title[0].setForeground(Color.red);

title[6].setForeground(Color.blue);

}

public void setShowDayTextField(JTextField [] text){

showDay=text;

for(int i=0;ishowDay.length;i++){

showDay[i].setFont(new Font("TimesRoman",Font.BOLD,15));

showDay[i].setHorizontalAlignment(JTextField.CENTER);

showDay[i].setEditable(false);

center.add(showDay[i]);

}

}

public void setCalendarMessage(CalendarMessage calendarMessage){

this.calendarMessage=calendarMessage;

}

public void showMonthCalendar(){

String [] a=calendarMessage.getMonthCalendar();

for(int i=0;i42;i++)

showDay[i].setText(a[i]);

validate();

}

}

关于java记事本代码和java记事本代码换行的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/14367.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载