跪求JAVA程序设计 跪求java 程序设计

作者&投稿:撒耿 (若有异议请与网页底部的电邮联系)
1,import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.awt.datatransfer.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;

public class JNotepad extends JPanel
{
JTextArea jta = new JTextArea("", 24, 40);

JScrollPane jsp = new JScrollPane(jta);

JMenuBar jmb = new JMenuBar();
JMenu file = new JMenu("File");
JMenu edit = new JMenu("Edit");
JMenu help = new JMenu("Help");
JMenu search = new JMenu("Search");

JToolBar toolBar = new JToolBar();

JMenuItem jmi;

Clipboard clipbd = getToolkit().getSystemClipboard();

PrinterJob prtMe = PrinterJob.getPrinterJob();

String text = "";

public JNotepad()
{
class newL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.setDocument(new PlainDocument());
}
}

class openL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int returnVal = fc.showDialog(JNotepad.this, "Open file");
if(returnVal == JFileChooser.APPROVE_OPTION)
{
String file = fc.getSelectedFile().getPath();
if(file == null)
{
return;
}
try
{
Reader in = new FileReader(file);
char[] buff = new char[4096];
int nch;
while((nch = in.read(buff, 0, buff.length)) != -1)
{
jta.setDocument(new PlainDocument());
jta.append(new String(buff, 0, nch));
}
}
catch (IOException io)
{
System.err.println("IOException: " + io.getMessage());
}
}
else
{
return;
}
}
}

class saveL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(JNotepad.this);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
String savefile = fc.getSelectedFile().getPath();
if(savefile == null)
{
return;
}
else
{
String docToSave = jta.getText();
if(docToSave != null)
{
FileOutputStream fstrm = null;
BufferedOutputStream ostrm = null;
try
{
fstrm = new FileOutputStream(savefile);
ostrm = new BufferedOutputStream(fstrm);
byte[] bytes = null;
try
{
bytes = docToSave.getBytes();
}
catch(Exception e1)
{
e1.printStackTrace();
}
ostrm.write(bytes);
}
catch(IOException io)
{
System.err.println("IOException: " +
io.getMessage());
}
finally
{
try
{
ostrm.flush();
fstrm.close();
ostrm.close();
}
catch(IOException ioe)
{
System.err.println("IOException: " +
ioe.getMessage());
}
}
}
}
}
else
{
return;
}
}
}

class pageSetupL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
prtMe.printDialog();
}
}

class printL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
prtMe.print();
}
catch(Exception ew)
{
}
}
}

class exitL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}

class copyL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String selection = jta.getSelectedText();
StringSelection clipString = new StringSelection(selection);
clipbd.setContents(clipString, clipString);
}
}

class cutL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String selection = jta.getSelectedText();
StringSelection clipString = new StringSelection(selection);
clipbd.setContents(clipString, clipString);
jta.replaceRange("", jta.getSelectionStart(),
jta.getSelectionEnd());
}
}

class pasteL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Transferable clipData = clipbd.getContents(JNotepad.this);
try
{
String clipString =
(String)clipData.getTransferData(
DataFlavor.stringFlavor);
jta.replaceRange(clipString,
jta.getSelectionStart(), jta.getSelectionEnd());
}
catch(Exception ex)
{
}
}
}

class deleteL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String selection = jta.getSelectedText();
jta.replaceRange("", jta.getSelectionStart(),
jta.getSelectionEnd());
}
}

class selectAllL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
jta.selectAll();
}
}

class findL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String find = "";
find = JOptionPane.showInputDialog(
"Find what: ");
}
}

class findNextL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}

class aboutL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null,
"JNotepad Developed By thyokel");
}
}

class jtaL implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}

file.add(jmi = new JMenuItem("New", KeyEvent.VK_N));
jmi.addActionListener(new newL());
file.add(jmi = new JMenuItem("Open", KeyEvent.VK_O));
jmi.addActionListener(new openL());
file.add(jmi = new JMenuItem("Save", KeyEvent.VK_S));
jmi.addActionListener(new saveL());
file.addSeparator();
file.add(jmi = new JMenuItem("Page Setup", KeyEvent.VK_G));
jmi.addActionListener(new pageSetupL());
file.add(jmi = new JMenuItem("Print", KeyEvent.VK_P));
jmi.addActionListener(new printL());
file.addSeparator();
file.add(jmi = new JMenuItem("Exit", KeyEvent.VK_X));
jmi.addActionListener(new exitL());

edit.add(jmi = new JMenuItem("Copy", KeyEvent.VK_C));
jmi.addActionListener(new copyL());
edit.add(jmi = new JMenuItem("Cut", KeyEvent.VK_T));
jmi.addActionListener(new cutL());
edit.add(jmi = new JMenuItem("Paste", KeyEvent.VK_P));
jmi.addActionListener(new pasteL());
edit.add(jmi = new JMenuItem("Delete", KeyEvent.VK_D));
jmi.addActionListener(new deleteL());
edit.addSeparator();
edit.add(jmi = new JMenuItem("Select All", KeyEvent.VK_A));
jmi.addActionListener(new selectAllL());

search.add(jmi = new JMenuItem("Find", KeyEvent.VK_F));
jmi.addActionListener(new findL());
search.add(jmi = new JMenuItem("Find Next", KeyEvent.VK_N));
jmi.addActionListener(new findNextL());

help.add(jmi = new JMenuItem("About", KeyEvent.VK_A));
jmi.addActionListener(new aboutL());

setLayout(new BorderLayout());
file.setMnemonic(KeyEvent.VK_F);
jmb.add(file);
edit.setMnemonic(KeyEvent.VK_E);
jmb.add(edit);
search.setMnemonic(KeyEvent.VK_S);
jmb.add(search);
jmb.add(Box.createHorizontalGlue());
help.setMnemonic(KeyEvent.VK_H);
jmb.add(help);

toolBar.setFloatable(true);
addButtons(toolBar);

add(jmb, BorderLayout.NORTH);
add(toolBar, BorderLayout.CENTER);
add(jsp, BorderLayout.SOUTH);

jta.getCaret().setVisible(true);
jta.setCaretPosition(0);
}

public static void main(String args[])
{
JFrame f = new JFrame();
JNotepad applet = new JNotepad();
f.setTitle("JNotepad");
f.setBackground(Color.lightGray);
f.getContentPane().add(applet, BorderLayout.CENTER);
f.addWindowListener(new appCloseL());
f.setSize(800, 500);
f.setVisible(true);
f.pack();
}

protected void addButtons(JToolBar toolBar)
{
JButton button = new JButton(new ImageIcon("images/new.gif"));
button.setToolTipText("Create a new document");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jta.setDocument(new PlainDocument());
}
});
toolBar.add(button);

JButton button1 = new JButton(new ImageIcon("images/open.gif"));
button1.setToolTipText("Open a document");
button1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int returnVal = fc.showDialog(JNotepad.this, "Open file");
if(returnVal == JFileChooser.APPROVE_OPTION)
{
String file = fc.getSelectedFile().getPath();
if(file == null)
{
return;
}
try
{
Reader in = new FileReader(file);
char[] buff = new char[4096];
int nch;
while((nch = in.read(buff, 0, buff.length)) != -1)
{
jta.setDocument(new PlainDocument());
jta.append(new String(buff, 0, nch));
}
}
catch (IOException io)
{
System.err.println("IOException: " + io.getMessage());
}
}
else
{
return;
}
}
});
toolBar.add(button1);

JButton button2 = new JButton(new ImageIcon("images/save.gif"));
button2.setToolTipText("Save the document");
button2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(JNotepad.this);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
String savefile = fc.getSelectedFile().getPath();
if(savefile == null)
{
return;
}
else
{
String docToSave = jta.getText();
if(docToSave != null)
{
FileOutputStream fstrm = null;
BufferedOutputStream ostrm = null;
try
{
fstrm = new FileOutputStream(savefile);
ostrm = new BufferedOutputStream(fstrm);
byte[] bytes = null;
try
{
bytes = docToSave.getBytes();
}
catch(Exception e1)
{
e1.printStackTrace();
}
ostrm.write(bytes);
}
catch(IOException io)
{
System.err.println("IOException: " +
io.getMessage());
}
finally
{
try
{
ostrm.flush();
fstrm.close();
ostrm.close();
}
catch(IOException ioe)
{
System.err.println("IOException: " +
ioe.getMessage());
}
}
}
}
}
else
{
return;
}
}
});
toolBar.add(button2);

JButton button3 = new JButton(new ImageIcon("images/copy.gif"));
button3.setToolTipText("Copy selected text");
button3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String selection = jta.getSelectedText();
StringSelection clipString = new StringSelection(selection);
clipbd.setContents(clipString, clipString);
}
});
toolBar.add(button3);

JButton button4 = new JButton(new ImageIcon("images/cut.gif"));
button4.setToolTipText("Cut selected text");
button4.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String selection = jta.getSelectedText();
StringSelection clipString = new StringSelection(selection);
clipbd.setContents(clipString, clipString);
jta.replaceRange("", jta.getSelectionStart(),
jta.getSelectionEnd());
}
});
toolBar.add(button4);

JButton button5 = new JButton(new ImageIcon("images/paste.gif"));
button5.setToolTipText("Paste clipboard");
button5.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Transferable clipData = clipbd.getContents(JNotepad.this);
try
{
String clipString =
(String)clipData.getTransferData(
DataFlavor.stringFlavor);
jta.replaceRange(clipString,
jta.getSelectionStart(), jta.getSelectionEnd());
}
catch(Exception ex)
{
}
}
});
toolBar.add(button5);

JButton button6 = new JButton(new ImageIcon("images/about.gif"));
button6.setToolTipText("About application");
button6.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null,
"JNotepad Developed By thyokel");
}
});
toolBar.add(button6);
}

protected static final class appCloseL extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}

谁有java经典编程300例完整版~

java编程的记事本:
import java.util.*;public class JieChengExample{public static void main(String args[]){Scanner input=new Scanner(System.in);int n,sum;Jiecheng jie=new Jiecheng();System.out.print("输入n的值:");//输入有几个阶乘相加n=input.nextInt();sum=0;for(int i=1;i<=n;i++){sum=sum+jie.jiecheng(i);//这是n个阶乘相加}System.out.println("1!+2!+3!+....+n!的和是:"+sum);}}class Jiecheng{public int jiecheng(int temp)//算阶乘的方法{int sum=1;for(int i=1;i<=temp;i++){sum=sum*i; //计算阶乘}return sum;//将一个阶乘返回}}
2.java赛马游戏:
import java.util.Random;public class Test {public static void main(String[] args) {Competition c = new Competition();Thread T = new Thread(c);T.start();}}class Competition implements Runnable{int red = 0;int green = 0;int Speed [] = new int [2];Competition(){}public void run(){Random r = new Random();for(int a= 0;a=500 || green>=500){if(red >=500){System.out.println("red先抵达终点线");}if(green >= 500){System.out.println("green先抵达终点线");}if(green ==500 && red ==500 ){System.out.println("两个同时到达");}return;}}/*if(red >green){System.out.println("Redwin"+red);}if(red=500 || green>=500){if(red >=500){System.out.println("red先抵达终点线");}if(green >= 500){System.out.println("green先抵达终点线");}if(green ==500 && red ==500 ){System.out.println("两个同时到达");}return;}}/*if(red >green){System.out.println("Redwin"+red);}if(red<green){System.out.println("Greenwin"+green);}if(red == green){System.out.println("equal");*/
JAVA的介绍:

Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。

class Rectangle
{
double h;
double w;
public Rectangle(double ww,double hh)
{
h=hh;
w=ww;
}
public void s()
{
double s=h*w;
System.out.print("该长方形面积为"+s+"
");
}
public void c()
{
double c=2*(h+w);
System.out.print("该长方形周长为"+c+"
");
}
}
public class TestRectangle
{
public static void main (String[] args) {
Rectangle tt=new Rectangle(5,4.7);
tt.s();
tt.c();
}
}

求java程序!!!大一的java课程设计题目,求高手送程序~~~求大家帮忙啊...
答:完整的Java程序:public class Test32 { public static void main(String[] args) { Complex c1 = new Complex(2, -1);Complex c2 = new Complex(3, 4);int m = 3;System.out.println(c1.toString() + "的绝对值:" + c1.abs());System.out.println(c1.toString() + "自增后:...

求简单的java设计程序,高分哦
答:输出上图的程序如下:public class Test { public static void main(String[] args) { final int N=5;for(int i=1;i<=N;i++){ for(int k=1;k<=N-i;k++){ System.out.print(" ");} for(int j=1;j<=i;j++){ System.out.print(j);} for(int j=i-1;j>=1;j--){ S...

用java写一个程序?
答:设计JAVA application程序,计算出20000000~300000000之间所有的素数,并将找到的素数写入primefile.dat文件,以下是一个使用Java语言编写的程序,可以计算出20000000~300000000之间所有的素数,并将找到的素数写入primefile.dat文件:javaCopy code import java.io.FileOutputStream; import java.io.IOException; ...

求程序JAVA设计圆柱体的类,计算其表面积和体积
答:import java.util.Scanner;interface JSolidFigure { //表面积 void SurfaceArea(); //体积 void Volume();}//圆柱class Cylinder implements JSolidFigure{ @Override public void SurfaceArea() { Scanner sc=new Scanner(System.in); System.out.println("请输入半径:")...

急!求程序!JAVA设计圆柱体的类,计算其表面积和体积
答:public class Cylinder {//圆柱体类private double radius;private double height;public Cylinder(){}//无参构造public Cylinder(double radius,double height){this.radius = radius;this.height = height;}public double getPerimeter(){//得到底圆周长return 2 * Math.PI * this.radius;}public ...

Java程序设计.在线等,求高手帮忙.
答:新建一个Student.java类,代码如下:public class Student { // 注册号、姓名、数学、外语、计算机课程成绩 private String id;private String name;private Integer maths;private Integer english;private Integer computer;public Student() { } public Student(String id, String name, Integer maths, ...

求Java语言高手帮忙设计程序
答:我给你简易计算机代码吧 import java.awt.Button;import java.awt.Frame;import java.awt.GridLayout;import java.awt.Panel;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;pub...

Java程序设计课程设计 学生信息管理系统 要求:使用图形用户界面用数据...
答:以下方法实现了学生界面设计 import java.awt.*;import java.awt.event.*;class StudentJieMian extends Frame implements ActionListener { MenuBar m=new MenuBar();//创建菜单栏 Menu m1=new Menu("信息");//创建菜单“信息”MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项 Menu...

java程序设计代码:显示一个三位整数的各位数字 输入一个整数,分别显示...
答:你好,按照你的要求代码如下,可以直接运行,并给出了运行结果:import java.util.Scanner;public class test { public static void main(String[] args) { // 获得用户输入 System.out.println("请输入一个数:");Scanner s = new Scanner(System.in);int i = s.nextInt();s.close();// ...

java程序设计 求大神解答
答:import java.awt.BorderLayout;import java.awt.Color;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;public class Test { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(400,300); JPanel jPanel = new J...