java 课程设计例子(Java 课设)

:暂无数据 2026-10-15 14:20:03 :0

java 课程设计例子(Java  课设)

大家好,今天小编来为大家解答以下的问题,关于java 课程设计例子,Java 课设这个很多人还不知道,现在让我们一起来看看吧!

本文目录

Java 课设

简单的五子棋程序
新建一个chess类,其中代码如下
package work;

import java.awt.Color;

public class Chess {
public static final int diamter=30;
private int x;//在网格中的索引,0~15
private int y;//在网格中的索引,0~15
private Color color;
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Chess(int x, int y, Color color) {
super();
this.x = x;
this.y = y;
this.color = color;
}

}
然后在同一个包中新建FirstFrame类。代码如下
package work;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

//主函数
public class FirstFrame{
public static void main(String args) {

FirstFrame1 f=new FirstFrame1();

f.setVisible(true);

}
}

//窗体函数
class FirstFrame1 extends JFrame implements ActionListener{
JMenuBar menuBar;
JMenu sysMenu;
JMenuItem startMenuItem;
JMenuItem backMenuItem;
JMenuItem exitMenuItem;
DrawPanel myPanel=new DrawPanel();

public FirstFrame1(){
super(“娃哈哈“);

add(myPanel);
menuBar=new JMenuBar();
setJMenuBar(menuBar);
sysMenu=new JMenu(“系统(s)“);
sysMenu.setMnemonic(’s’);
menuBar.add(sysMenu);
startMenuItem=new JMenuItem(“开始“);
backMenuItem=new JMenuItem(“悔棋“);
exitMenuItem=new JMenuItem(“退出“);
sysMenu.add(startMenuItem);
sysMenu.add(backMenuItem);
sysMenu.addSeparator();
sysMenu.add(exitMenuItem);
startMenuItem.addActionListener(this);
backMenuItem.addActionListener(this);
exitMenuItem.addActionListener(this);

super.setSize(600,650);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e){
Object obj=e.getSource();
if(obj==startMenuItem){
myPanel.start(); //DrawPanel p=new DrawPanel();是错的;
}else if(obj==backMenuItem){
myPanel.back();
}else{
System.exit(0);
}

}

}
最后新建一个DrawPanel类代码如下
package work;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import sun.awt.geom.AreaOp.AddOp;

//画柄;
class DrawPanel extends JPanel implements MouseListener,MouseMotionListener{
final int MARGIN_TOP=60;
final int MARGIN_LEFT=30;
final int CELL_WIDTH=35;
final int COLS=15;
final int ROWS=15;
Chess chessList=new Chess[(COLS+1)*(ROWS+1)];
int chessCount=0;
boolean isBlack=true;
boolean gameOver=false;

public DrawPanel(){ //构造函数
Color color=new Color(200,250,200);
setBackground(color);
this.addMouseMotionListener(this);
this.addMouseListener(this);
}
public void start(){
for(int i=0;i《chessList.length;i++)
chessList[i]=null;
isBlack=true;
gameOver=false;
chessCount=0;
repaint();
}
public void back(){
if (chessCount==0||gameOver==true)
return;
chessList[chessCount-1]=null;

chessCount--;
isBlack=!isBlack;

repaint();
}
@Override

protected void paintComponent(Graphics g) { //方法重写
// TODO Auto-generated method stub
super.paintComponent(g);
for(int i=0;i《=ROWS;i++){
g.drawLine(MARGIN_LEFT, MARGIN_TOP+i*CELL_WIDTH, MARGIN_LEFT+COLS*CELL_WIDTH, MARGIN_TOP+i*CELL_WIDTH);
}
for(int i=0;i《=COLS;i++){
g.drawLine(MARGIN_LEFT+i*CELL_WIDTH, MARGIN_TOP, MARGIN_LEFT+i*CELL_WIDTH, MARGIN_TOP+ROWS*CELL_WIDTH);
}
for(int i=0;i《chessCount;i++){ //绘制棋子数组
Chess chess=chessList[i];
int xPos=MARGIN_LEFT+CELL_WIDTH*chess.getX()-Chess.diamter/2;
int yPos=MARGIN_TOP+CELL_WIDTH*chess.getY()-Chess.diamter/2;
g.setColor(chess.getColor());
g.fillOval(xPos,yPos, Chess.diamter, Chess.diamter);
if(i==chessCount-1){
g.setColor(Color.red);
g.drawRect(xPos, yPos, Chess.diamter, Chess.diamter);
}
}
if(isBlack)
g.setColor(Color.black);
else
g.setColor(Color.white);
g.fillOval(8*CELL_WIDTH, CELL_WIDTH/2,Chess.diamter, Chess.diamter);
String colorStr=isBlack==false?“白方下“:“黑方下“;
g.setColor(Color.blue);
g.drawString(colorStr+“ 第“+chessCount/2+“步“, 9*CELL_WIDTH, CELL_WIDTH);
}

public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}

public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
super.setCursor(new Cursor(Cursor.HAND_CURSOR));
int x=(e.getX()-MARGIN_LEFT+Chess.diamter/2)/CELL_WIDTH;
int y=(e.getY()-MARGIN_TOP+Chess.diamter/2)/CELL_WIDTH;
if(x《0||y《0||x》COLS||y》ROWS) //超出棋盘边界
super.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

if(findChess(x,y)) //下过的地方不能再下
super.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if(gameOver)
super.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}

public void mousePressed(MouseEvent e) {

int x=(e.getX()-MARGIN_LEFT+Chess.diamter/2)/CELL_WIDTH;
int y=(e.getY()-MARGIN_TOP+Chess.diamter/2)/CELL_WIDTH;
if(x《0||y《0||x》COLS||y》ROWS) //超出棋盘边界
return;
Color color=Color.black;
if(!isBlack) // 变颜色
color=Color.white;
if(findChess(x,y)) //下过的地方不能再下
return;
if(gameOver)
return;
chessList[chessCount]=new Chess(x,y,color);
repaint(); //重绘
isBlack=!isBlack;
chessCount++;
String colorStr=color==Color.white?“白方“:“黑方“;
int count={0,0,0,0};
for(int i=x-1;i》=0;i--){
if(findChess(i,y,color)){
count++;
}
else
break;
}
for(int i=x+1;i《=COLS;i++){
if(findChess(i,y,color)){
count++;
}
else
break;
}
for(int i=y-1;i》=0;i--){
if(findChess(x,i,color)){
count++;
}
else
break;
}
for(int i=y+1;i《=ROWS;i++){
if(findChess(x,i,color)){
count++;
}
else
break;
}
for(int i=x+1,j=y+1;i《=COLS&&j《=ROWS;i++,j++){
if(findChess(i,j,color)){
count++;
}
else
break;
}
for(int i=x-1,j=y-1;i》=0&&j》=0;i--,j--){
if(findChess(i,j,color)){
count++;
}
else
break;
}
for(int i=x+1,j=y-1;i《=COLS&&j》=0;i++,j--){

if(findChess(i,j,color)){
count++;
}
else
break;
}
for(int i=x-1,j=y+1;i》=0&&j《=ROWS;i--,j++){
if(findChess(i,j,color)){
count++;
}
else
break;
}
for(int i=0;i《4;i++){

if(count[i]》=4){
gameOver=true;
JOptionPane.showMessageDialog(this, “恭喜“+colorStr+“胜利“);
return;
}
}
System.out.println(e.getX()+“,“+e.getY());

}

public boolean findChess(int x,int y){
for(int i=0;i《chessCount;i++){
if(chessList[i].getX()==x && chessList[i].getY()==y)
return true;
}
return false;
}

public boolean findChess(int x,int y,Color color){
for(int i=0;i《chessCount;i++){
if(chessList[i].getX()==x && chessList[i].getY()==y && chessList[i].getColor()==color)
return true;
}
return false;
}

}

Java课程设计!急!!!(高分)

我帮你编写了一部分,实现了“输入十个同学的相关信息,并在文本框中显示”(图形界面实现)。

要实现接下去的功能其实也真的不难的,但是真的很麻烦、很浪费时间……我就帮你做到这里了,你自己添加一下代码就可以(或者提高悬赏的话可以考虑考虑啊!哈哈……)代码如下:

import java.awt.BorderLayout;

import javax.swing.JPanel;

import javax.swing.JFrame;

import java.awt.Dimension;

import javax.swing.JButton;

import java.awt.Rectangle;

import javax.swing.JLabel;

import javax.swing.SwingConstants;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.JOptionPane;

public class TongJi extends JFrame {

 private static final long serialVersionUID = 1L;

 private JPanel jContentPane = null;

 private JButton jButton = null;

 private JLabel jLabel = null;

 private JScrollPane jScrollPane = null;

 private JTextArea jTextArea = null;

 /**

  * This is the default constructor

  */

 public TongJi() {

  super();

  initialize();

 }

 /**

  * This method initializes this

  * 

  * @return void

  */

 private void initialize() {

  this.setSize(412, 372);

  this.setContentPane(getJContentPane());

  this.setTitle(“成绩统计“);

  this.addWindowListener(new java.awt.event.WindowAdapter() {

   public void windowClosing(java.awt.event.WindowEvent e) {

    System.exit(0);

   }

  });

  this.setVisible(true);

 }

 /**

  * This method initializes jContentPane

  * 

  * @return javax.swing.JPanel

  */

 private JPanel getJContentPane() {

  if (jContentPane == null) {

   jLabel = new JLabel();

   jLabel.setBounds(new Rectangle(18, 66, 65, 18));

   jLabel.setHorizontalAlignment(SwingConstants.CENTER);

   jLabel.setText(“统计结果:“);

   jContentPane = new JPanel();

   jContentPane.setLayout(null);

   jContentPane.add(getJButton(), null);

   jContentPane.add(jLabel, null);

   jContentPane.add(getJScrollPane(), null);

  }

  return jContentPane;

 }

 /**

  * This method initializes jButton 

  *  

  * @return javax.swing.JButton 

  */

 private JButton getJButton() {

  if (jButton == null) {

   jButton = new JButton();

   jButton.setBounds(new Rectangle(18, 16, 86, 28));

   jButton.setText(“开始统计“);

   jButton.addActionListener(new java.awt.event.ActionListener() {

    public void actionPerformed(java.awt.event.ActionEvent e) {

     /////录入成绩信息

     String mymsg=new String;

     for(int i=0;i《10;i++){

      String strnum=JOptionPane.showInputDialog(null, “请输入第“+(i+1)+“个学生的学号“, “信息录入“, JOptionPane.WARNING_MESSAGE);

      String strname=JOptionPane.showInputDialog(null, “请输入第“+(i+1)+“个学生的姓名“, “信息录入“, JOptionPane.WARNING_MESSAGE);

      String doublemath=JOptionPane.showInputDialog(null, “请输入第“+(i+1)+“个学生的数学成绩“, “信息录入“, JOptionPane.WARNING_MESSAGE);

      String doubleeng=JOptionPane.showInputDialog(null, “请输入第“+(i+1)+“个学生的英语成绩“, “信息录入“, JOptionPane.WARNING_MESSAGE);

      String doublejava=JOptionPane.showInputDialog(null, “请输入第“+(i+1)+“个学生的JAVA成绩“, “信息录入“, JOptionPane.WARNING_MESSAGE);

      String doublecomp=JOptionPane.showInputDialog(null, “请输入第“+(i+1)+“个学生的计算机成绩“, “信息录入“, JOptionPane.WARNING_MESSAGE);

      mymsg[i]=strnum;

      mymsg[i]=strname;

      mymsg[i]=doublemath;

      mymsg[i]=doubleeng;

      mymsg[i]=doublejava;

      mymsg[i]=doublecomp;

     }

     ////显示成绩信息

     jTextArea.setText(“学号    姓名    数学    英语    JAVA    计算机“);

     for(int i=0;i《10;i++){

      jTextArea.setText(jTextArea.getText()+“\r\n“);

      for(int j=0;j《6;j++){

       jTextArea.setText(jTextArea.getText()+mymsg[i][j]+“    “);

      }

     }

    }

   });

  }

  return jButton;

 }

 /**

  * This method initializes jScrollPane 

  *  

  * @return javax.swing.JScrollPane 

  */

 private JScrollPane getJScrollPane() {

  if (jScrollPane == null) {

   jScrollPane = new JScrollPane();

   jScrollPane.setBounds(new Rectangle(18, 86, 370, 230));

   jScrollPane.setViewportView(getJTextArea());

  }

  return jScrollPane;

 }

 /**

  * This method initializes jTextArea 

  *  

  * @return javax.swing.JTextArea 

  */

 private JTextArea getJTextArea() {

  if (jTextArea == null) {

   jTextArea = new JTextArea();

   jTextArea.setEditable(false);

  }

  return jTextArea;

 }

 public static void main(String args){

  new TongJi();

 }

}  //  @jve:decl-index=0:visual-constraint=“10,10“

效果如下图:

java课程设计(符合要求,别太深奥)

俄罗斯方块没有 有自己做的贪食蛇

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

public class GameMain extends JFrame implements Runnable {

int runY = 140;

int runX = 120;

int width = 600;

int height = 500;

int W = 10;

int M = 10;

int fangxiang = 0;

int sheshen = new int;

int foodx = 150;

int foody = 150;

int score = 0;

boolean zhuangtai = true;

class UsurKey extends KeyAdapter {

public void keyPressed(KeyEvent e) {
fangxiang = e.getKeyCode();
}

}

class UsurMouse extends MouseAdapter {

public void mouseClicked(MouseEvent e) {
System.out.println(e.getX() + “,“ + e.getY());
}
}

public GameMain() {
this.setSize(width, height);
this.setVisible(true);
this.addKeyListener(new UsurKey());
this.addMouseListener(new UsurMouse());
new Thread(this).start();
for (int i = 0; i 《 W; i++) {
sheshen[i * 2] = runX + i * W;
sheshen[i * 2 + 1] = runY;
}
}

public static void main(String args) {
GameMain g = new GameMain();
}

int count = 0;

public void paint(Graphics g) {
g.fillRect(0, 0, width, height);
g.setColor(new Color(155, 155, 155));
try {
File file1 = new File(“img/�0�8�0�8.jpg“);
Image image = ImageIO.read(file1);
g.drawImage(image, 150, 100, null);
} catch (IOException e) {
e.printStackTrace();
}
g.drawRect(20, 50, width - 40, height - 100);
g.setColor(new Color(133, 195, 95));
for (int i = 0; i 《 W; i++) {
g.fillRect(sheshen[i * 2], sheshen[i * 2 + 1], 10, 10);
}
g.setColor(new Color(255,255,0));
count++;
if(count%2==0){
g.fillRect(foodx, foody, M, M);
}
}

public void updata() {
if (fangxiang == KeyEvent.VK_UP) {
runY = runY - 10;
}
if (fangxiang == KeyEvent.VK_DOWN) {
runY = runY + 10;
}
if (fangxiang == KeyEvent.VK_RIGHT) {
runX = runX + 10;
}
if (fangxiang == KeyEvent.VK_LEFT) {
runX = runX - 10;
}

for (int i = W - 1; i 》 0; i--) {
sheshen[i * 2] = sheshen[(i - 1) * 2];
sheshen[i * 2 + 1] = sheshen[(i - 1) * 2 + 1];
}
sheshen = runX;
sheshen = runY;
if (sheshen 《= 20 || sheshen + W 》= 580) {
zhuangtai = false;
}
if (sheshen 《= 50 || sheshen + W 》= 450) {
zhuangtai = false;
}
Random rand= new Random();
if(sheshen==foodx&&sheshen==foody){
W++;
while(true){
foodx = Math.abs((rand.nextInt()%(50 + width-100 -10))/10*10);
foody = Math.abs((rand.nextInt()%(50 + height-100 -10))/10*10);
if(foodx》60&&foody》60){
boolean flag=true;
for(int i=0;i《W;i++){
if(sheshen[2*i] == foodx && sheshen[2*i+1] == foody){
flag=false;
}
}
if(flag){
break;
}
}
}
}
}

public void run() {
while (zhuangtai) {
try {
updata();
this.repaint();
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
}

java 课程设计

//父类MyMedia
public class MyMedia{
protected String mediaName;
protected float price;
protected String press;
protected String artist;

public MyMedia(String mn,float pri,String pre,String art){
mediaName=mn;
price=pri;
press=pre;
artist=art;
}
public void mediaNameInput(String mn){
mediaName=mn;
}
public void mediaPriceInput(float pri){
price=pri;
}
public void mediaPressInput(String pre){
press=pre;
}
public void mediaArtistInput(String art){
artist=art;
}
}

//子类MyBook
public class MyBook extends MyMedia{
private String editor;
private String publishDate;
private String bookISBN;

public MyBook(String mn,float pri,String pre,String art,String edi,String pub,String isbn){
super(mn,pri,pre,art);
editor=edi;
publishDate=pub;
bookISBN=isbn;
}
public void bookOtherInfo(String edi,String pub,String isbn){
editor=edi;
publishDate=pub;
bookISBN=isbn;
}
public void getBookInfo(){
System.out.println();
System.out.println(“书名: “+mediaName);
System.out.println(“书的价格:“+price);
System.out.println(“书的出版社:“+press);
System.out.println(“书的作者:“+artist);
System.out.println(“书的editor:“+editor);
System.out.println(“书的出版日期:“+publishDate);
System.out.println(“书的bookISBN:“+bookISBN);
}
}

//子类MyCD
public class MyCD extends MyMedia{
private String cdISRC;
private String cdPublisher;

public MyCD(String mn,float pri,String pre,String art,String isrc,String cdp){
super(mn,pri,pre,art);
cdISRC=isrc;
cdPublisher=cdp;
}
public void CDOtherInfo(String isrc,String cdp){
cdISRC=isrc;
cdPublisher=cdp;
}
public void getCDInfo(){
System.out.println();
System.out.println(“CD名: “+mediaName);
System.out.println(“CD的价格:“+price);
System.out.println(“CD的出版社:“+press);
System.out.println(“CD的演唱者:“+artist);
System.out.println(“CD的cdISRC:“+cdISRC);
System.out.println(“CD的发行者:“+cdPublisher);
}
}

//子类MyTape
public class MyTape extends MyMedia{
private String TapeISRC;

public MyTape(String mn,float pri,String pre,String art,String isrc){
super(mn,pri,pre,art);
TapeISRC=isrc;
}
public void TapeOtherInfo(String isrc){
TapeISRC=isrc;
}
public void getTapeInfo(){
System.out.println();
System.out.println(“CD名: “+mediaName);
System.out.println(“CD的价格:“+price);
System.out.println(“CD的出版社:“+press);
System.out.println(“CD的演唱者:“+artist);
System.out.println(“CD的TapeISRC:“+TapeISRC);
}
}

未完代叙 时间太晚了!!
QQ 383513327

Java课程设计

感觉不是特别麻烦。
文件系统是什么?就是读取个特殊文件吗?要解码?
界面建议你就用windowbuilder直接做吧,简单点。
要看到结果,选择题的好看,问题怎么判断。再来个论述题。
把要求写详细点。

java课程设计----记事本

//package net.src.net;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.color.*;
import java.awt.font.*;
import javax.swing.undo.*;

public class Note extends JFrame
{
boolean isChange=false;
boolean wasChange=false;
JMenuBar menuBar=new JMenuBar();

JMenu menuFile=new JMenu(“File“);
JMenuItem menuFileOpen=new JMenuItem(“Open..“);
JMenuItem menuFileSave=new JMenuItem(“Save..“);
JMenuItem menuFileExit=new JMenuItem(“Exit“);

JMenu menuEdit=new JMenu(“Edit“);
JMenuItem menuFileCut=new JMenuItem(“Cut“);
JMenuItem font=new JMenuItem(“Font“);
JMenuItem menuFilePaste=new JMenuItem(“Paste“);

JTextArea fileArea=new JTextArea();

public Note()
{
this.setTitle(“记事本“);
Toolkit tool=this.getToolkit();//窗口图标!
Image myimage=tool.getImage(“戒指.jpg“);
this.setIconImage(myimage);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
exit();
}
});
menuFileOpen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileOpen_actionPerformed(e);
}
});
menuFileSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileSave_actionPerformed(e);
}
});
menuFileExit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileExit_actionPerformed(e);
}
});
menuFileCut.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileCut_actionPerformed(e);
}
});
menuFilePaste.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
filePaste_actionPerformed(e);
}
});
font.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
fileColor_actionPerformed(e);
}
});
fileArea.getDocument().addDocumentListener(new DocumentListener()
{
public void insertUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
public void removeUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
public void changedUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
});
setSize(500,450);
menuBar.add(menuFile);
menuFile.setMnemonic(’F’);
menuBar.add(menuEdit);
menuEdit.setMnemonic(’E’);
menuFile.add(menuFileOpen);
menuFileOpen.setMnemonic(’O’);//访问健;
menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));//快捷健;
menuFile.add(menuFileSave);
menuFileSave.setMnemonic(’S’);
menuFileSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
menuFile.addSeparator();
menuFile.add(menuFileExit);
menuFileExit.setMnemonic(’E’);
menuEdit.add(menuFileCut);
menuFileCut.setMnemonic(’C’);
menuFileCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
menuEdit.add(menuFilePaste);
menuFilePaste.setMnemonic(’P’);
menuFilePaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_MASK));
menuEdit.add(font);
font.setMnemonic(’N’);
font.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
this.getContentPane().add(new JScrollPane(fileArea));
setJMenuBar(menuBar);
fileArea.setLineWrap(true);
}
public void fileExit_actionPerformed(ActionEvent e)
{
System.exit(0);
}
public void fileOpen_actionPerformed(ActionEvent e)
{
//以下是filter;
JFileChooser fileChooser=new JFileChooser();
//fileChooser.addChoosableFileFilter(new myFilter(“*.txt“,“Files(*.txt)“));
fileChooser.addChoosableFileFilter(fileChooser.getFileFilter());
if(fileChooser.APPROVE_OPTION!=fileChooser.showOpenDialog(this))return;
//以下是文件读
BufferedReader dataIn=null;
try
{
dataIn=new BufferedReader(new FileReader(fileChooser.getSelectedFile().getPath()));
String c=null;
do
{
c=dataIn.readLine();
if(c!=null)
fileArea.append(c+“\n“);
}
while(c!=null);
}
catch(Exception ex)
{
System.out.println(“Catch exception:“+ex.toString());
}
}
public void exit()
{
if(isChange==false)
System.exit(1);
else
{
int decision=JOptionPane.showConfirmDialog(this,“The File has Change.\n“+“Do you want to save the change?“,
“Notepad“,JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);
if (decision == JOptionPane.YES_OPTION)
{
//以下是将文件写入计算机!
try {
JFileChooser fileSave = new JFileChooser();
fileSave.setDialogTitle(“保存文件“);
//fileSave.addChoosableFileFilter(new myFilter(“*.txt“,“Files(*.txt)“));
fileSave.addChoosableFileFilter(fileSave.getFileFilter());
if (fileSave.APPROVE_OPTION != fileSave.showSaveDialog(this))
return;
BufferedWriter dataOut = new BufferedWriter(new BufferedWriter(new
FileWriter(fileSave.getSelectedFile())));
String c = null;
do {
String str = fileArea.getText();
dataOut.write(str);
dataOut.close();
}
while (c != null);
}
catch (Exception e2) {
System.out.println(“Catch exception:有错误!“ + e2.toString());
}
}
else if (decision == JOptionPane.NO_OPTION)
System.exit(1);
else if (decision == JOptionPane.CANCEL_OPTION);
;
}
//innerclass.fileSave_actionPerformed();
}
public void fileSave_actionPerformed(ActionEvent e1)
{

//以下是将文件写入计算机!
try
{
JFileChooser fileSave=new JFileChooser();
fileSave.setDialogTitle(“保存文件“ );
//fileSave.addChoosableFileFilter(new myFilter(“*.txt“,“Files(*.txt)“));
fileSave.addChoosableFileFilter(fileSave.getFileFilter());
if(fileSave.APPROVE_OPTION!=fileSave.showSaveDialog(this))return;
BufferedWriter dataOut=new BufferedWriter(new BufferedWriter(new FileWriter(fileSave.getSelectedFile()+“.txt“)));
//RandomAccessFile dataOut=new RandomAccessFile(fileSave.getSelectedFile(),“rw“);
String c=null;
do
{
String str=fileArea.getText();
dataOut.write(str);
dataOut.close();
}
while(c!=null);
}
catch(Exception e2)
{
System.out.println(“Catch exception:有错误!“+e2.toString());
}
}
public static void main(String arg)
{
Note nt=new Note();
nt.show();
}
public void fileCut_actionPerformed(ActionEvent e)
{
fileArea.cut();
}
public void filePaste_actionPerformed(ActionEvent e)
{
fileArea.paste();
}
public void fileColor_actionPerformed(ActionEvent e)
{
JColorChooser fileColor=new JColorChooser();
//fileArea.setForeground(fileColor.showDialog(this,“颜色“,Color.red));
//fileArea.setSelectionColor(fileColor.showDialog(this,“颜色“,Color.red));
fileArea.setSelectionColor(fileColor.showDialog(this,“颜色“,Color.black));
}
}

关于java 课程设计例子,Java 课设的介绍到此结束,希望对大家有所帮助。

java 课程设计例子(Java  课设)

本文编辑:admin

更多文章:


php和前端哪个好学(php和前端哪个好学就这个问题回答下,回答php或者前端,谢谢大家了)

php和前端哪个好学(php和前端哪个好学就这个问题回答下,回答php或者前端,谢谢大家了)

其实php和前端哪个好学的问题并不复杂,但是又很多的朋友都不太了解php和前端哪个好学就这个问题回答下,回答php或者前端,谢谢大家了,因此呢,今天小编就来为大家分享php和前端哪个好学的一些知识,希望可以帮助到大家,下面我们一起来看看这个

2026年10月15日 15:10

java 课程设计例子(Java  课设)

java 课程设计例子(Java 课设)

大家好,今天小编来为大家解答以下的问题,关于java 课程设计例子,Java 课设这个很多人还不知道,现在让我们一起来看看吧!

2026年10月15日 14:20

jquery validate官网(jquery 的validate\form等插件问题)

jquery validate官网(jquery 的validate\form等插件问题)

各位老铁们,大家好,今天由我来为大家分享jquery validate官网,以及jquery 的validate\form等插件问题的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站,您的支持是我们最大的动力,谢谢大

2026年10月15日 13:40

eclipse快捷键代码(请问eclipse中输出的快捷键是什么)

eclipse快捷键代码(请问eclipse中输出的快捷键是什么)

本篇文章给大家谈谈eclipse快捷键代码,以及请问eclipse中输出的快捷键是什么对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

2026年10月15日 12:50

conflict怎么记忆(请问conflict在英文修辞手法中应该怎么样解释)

conflict怎么记忆(请问conflict在英文修辞手法中应该怎么样解释)

今天给各位分享请问conflict在英文修辞手法中应该怎么样解释的知识,其中也会对请问conflict在英文修辞手法中应该怎么样解释进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

2026年10月15日 12:40

计算机四大核心课程(计算机课程有哪些)

计算机四大核心课程(计算机课程有哪些)

其实计算机四大核心课程的问题并不复杂,但是又很多的朋友都不太了解计算机课程有哪些,因此呢,今天小编就来为大家分享计算机四大核心课程的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!

2026年10月15日 12:20

python语言程序设计是什么(python语言是什么)

python语言程序设计是什么(python语言是什么)

各位老铁们好,相信很多人对python语言程序设计是什么都不是特别的了解,因此呢,今天就来为大家分享下关于python语言程序设计是什么以及python语言是什么的问题知识,还望可以帮助大家,解决大家的一些困惑,下面一起来看看吧!

2026年10月15日 12:00

windows程序设计第五版(《WINDOWS程序设计》和《WINDOWS核心编程》的区别)

windows程序设计第五版(《WINDOWS程序设计》和《WINDOWS核心编程》的区别)

本篇文章给大家谈谈windows程序设计第五版,以及《WINDOWS程序设计》和《WINDOWS核心编程》的区别对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了

2026年10月15日 11:30

issued retroactively(FORM E上盖“ISSUED RETROACTIVELY”的问题,小女在线等待)

issued retroactively(FORM E上盖“ISSUED RETROACTIVELY”的问题,小女在线等待)

各位老铁们,大家好,今天由我来为大家分享issued retroactively,以及FORM E上盖“ISSUED RETROACTIVELY”的问题,小女在线等待的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站

2026年10月15日 10:30

f发音是什么?printf的返回值是什么

f发音是什么?printf的返回值是什么

大家好,关于f很多朋友都还不太明白,不过没关系,因为今天小编就来为大家分享关于f发音是什么的知识点,相信应该可以解决大家的一些困惑和问题,如果碰巧可以解决您的问题,还望关注下本站哦,希望对各位有所帮助!

2026年10月15日 10:10

最近更新

java 课程设计例子(Java  课设)
2026-10-15 14:20:03 浏览:0
jquery validate官网(jquery 的validate\form等插件问题)
2026-10-15 13:40:03 浏览:0
热门文章

标签列表