求助:JAVA小程序

求助:JAVA小程序,第1张

分类: 电脑/网络 >> 程序设计 >> 其他编程语言

问题描述:

我们修的汇编语言是JAVA,怎奈自己学术不精现在此象高手请教小程序是期末做课程设计用的题目有日历记事本,学籍管理系统,计算器,画图程序其他的也可以现需要两个程序,谢谢大家!

解析:

import javaio;

import javautilCalendar;

import javaawt;

import javaawtevent;

import javaxswing;

public class NoteBook extends JFrame implements ActionListener,ItemListener,WindowListener,MouseListener{

Container c = thisgetContentPane();

JMenuBar jmb = new JMenuBar();

JColorChooser jcc = new JColorChooser();

JMenu jm1 = new JMenu("文件(F)");

JMenu jm2 = new JMenu("编辑(E)");

JMenu jm3 = new JMenu("格式(O)");

JMenu jm4 = new JMenu("查看(V)");

JMenu jm5 = new JMenu("帮助(H)");

JMenuItem jmi1 = new JMenuItem("新建(N)");

JMenuItem jmi2 = new JMenuItem("打开(O)");

JMenuItem jmi3 = new JMenuItem("保存(S)");

JMenuItem jmi4 = new JMenuItem("退出(X)");

JMenuItem jmi5 = new JMenuItem("撤消(U)");

JMenuItem jmi6 = new JMenuItem("复制(C)");

JMenuItem jmi7 = new JMenuItem("粘贴(P)");

JMenuItem jmi8 = new JMenuItem("剪切(T)");

JMenuItem jmi12 = new JMenuItem("日期和时间");

JMenuItem jmi9 = new JMenuItem("字体(E)");

JCheckBoxMenuItem jcbmi = new JCheckBoxMenuItem("自动换行(W)");

JMenuItem jmi10 = new JMenuItem("删除(S)");

JMenuItem jmi11 = new JMenuItem("背景颜色(H)");

JTextArea jta = new JTextArea(15,15);

JScrollPane jsp = new JScrollPane(jta);

PupolMenu pm = new Pupolmenu();

NoteBook(){

thisaddWindowListener(this);

csetLayout(new BorderLayout());

cadd(jmb,BorderLayoutNORTH);

thissetTitle("新建 文本文档");

jmbadd(jm1);

jm1setMnemonic('f');

jm1addActionListener(this);

jmbadd(jm2);

jm2setMnemonic('e');

jmbadd(jm3);

jm3setMnemonic('o');

jmbadd(jm4);

jm4setMnemonic('v');

jmbadd(jm5);

jm5setMnemonic('h');

jm1add(jmi1);

jmi1addActionListener(this);

jmi1setAccelerator(KeyStrokegetKeyStroke('N',EventCTRL_MASK,false));

jm1addSeparator();

jm1add(jmi2);

jmi2setAccelerator(KeyStrokegetKeyStroke('O',EventCTRL_MASK,false));

jmi2addActionListener(this);

jm1addSeparator();

jm1add(jmi3);

jmi3setAccelerator(KeyStrokegetKeyStroke('S',EventCTRL_MASK,false));

jmi3addActionListener(this);

jm1addSeparator();

jm1add(jmi4);

jmi1setMnemonic('n');

jmi2setMnemonic('o');

jmi3setMnemonic('s');

jmi4setMnemonic('x');

jmi4addActionListener(this);

jm2add(jmi5);

jm2addSeparator();

jm2add(jmi6);

jm2addSeparator();

jm2add(jmi7);

jm2addSeparator();

jm2add(jmi8);

jm2add(jmi12);

jmi12addActionListener(this);

jm3add(jcbmi);

jcbmiaddItemListener(this);

jm3addSeparator();

jm3add(jmi9);

jm4add(jmi10);

jmi10addActionListener(this);

jm5add(jmi11);

jmi11addActionListener(this);

cadd(jsp);

thissetDefaultCloseOperation(JFrameDISPOSE_ON_CLOSE);

thissetSize(500,500);

thissetVisible(true);

}

public void actionPerformed(ActionEvent e){

if(egetSource()==jmi1){

jtasetText("");

thissetTitle("无标题 - 记事本");

}

if(egetSource()==jmi2){

File f1;

JFileChooser jfc1 = new JFileChooser();

int num1 = jfc1showOpenDialog(this);

if(num1==JFileChooserAPPROVE_OPTION){

try{

f1 = jfc1getSelectedFile();

thissetTitle(f1getName());

FileReader fr = new FileReader(f1);

BufferedReader br = new BufferedReader(fr);

String str;

while((str = brreadLine())!=null){

jtasetText(str);

}

frclose();

brclose();

}catch(FileNotFoundException e1){

e1printStackTrace();

}catch(IOException e2){

e2printStackTrace();

}

}

}

if(egetSource()==jmi3){

File f2 = null;

JFileChooser jfc2 = new JFileChooser();

int num2 = jfc2showSaveDialog(this);

if(num2==JFileChooserAPPROVE_OPTION){

f2=jfc2getSelectedFile();

thissetTitle(f2getName());

try{

FileWriter fw = new FileWriter(f2);

BufferedWriter bw = new BufferedWriter(fw);

bwwrite(jtagetText());

bwclose();

fwclose();

}catch(IOException e2){

e2printStackTrace();

}

}

}

if(egetSource()==jmi4){

int a = JOptionPaneshowConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPaneYES_NO_CANCEL_OPTION);

if(a==1){

thisdispose();

}else if(a==0){

File f2 = null;

JFileChooser jfc2 = new JFileChooser();

int num2 = jfc2showSaveDialog(this);

if(num2==JFileChooserAPPROVE_OPTION){

f2=jfc2getSelectedFile();

thissetTitle(f2getName());

try{

FileWriter fw = new FileWriter(f2);

BufferedWriter bw = new BufferedWriter(fw);

bwwrite(jtagetText());

bwclose();

fwclose();

}catch(IOException e2){

e2printStackTrace();

}

thisdispose();

}

}

}

if(egetSource()==jmi12){

Calendar c1 =CalendargetInstance();

int y = c1get(CalendarYEAR);

int m = c1get(CalendarMONTH);

int d = c1get(CalendarDATE);

int h = c1get(CalendarHOUR);

int m1 = c1get(CalendarMINUTE);

int m2 = m+1;

jtasetText(y+"年"+m2+"月"+d+"日"+h+":"+m1);

}

if(egetSource()==jmi11){

Color ccc = JColorChoosershowDialog(this,"color",ColorBLACK);

jtasetSelectedTextColor(ccc);

jtasetBackground(ccc);

}

if(egetSource()==jmi10){

jtareplaceRange("",jtagetSelectionStart(),jtagetSelectionEnd());

}

}

public void itemStateChanged(ItemEvent e2){

if(e2getItemSelectable()==jcbmi){

jtasetLineWrap(true);

}else

jtasetLineWrap(false);

}

public static void main(String[] args){

new NoteBook();

}

public void windowOpened(WindowEvent arg0) {

}

public void windowClosing(WindowEvent arg0) {

int a = JOptionPaneshowConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPaneYES_NO_CANCEL_OPTION);

if(a==1){

thisdispose();

}else if(a==0){

File f2 = null;

JFileChooser jfc2 = new JFileChooser();

int num2 = jfc2showSaveDialog(this);

if(num2==JFileChooserAPPROVE_OPTION){

f2=jfc2getSelectedFile();

thissetTitle(f2getName());

try{

FileWriter fw = new FileWriter(f2);

BufferedWriter bw = new BufferedWriter(fw);

bwwrite(jtagetText());

bwclose();

fwclose();

}catch(IOException e2){

e2printStackTrace();

}

}

if(a==2){

/

}

}

}

public void windowClosed(WindowEvent arg0) {

}

public void windowIconified(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void windowDeiconified(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void windowActivated(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void windowDeactivated(WindowEvent arg0) {

TODO Auto-generated method stub

}

public void mouseClicked(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mousePressed(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mouseReleased(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mouseEntered(MouseEvent arg0) {

TODO Auto-generated method stub

}

public void mouseExited(MouseEvent arg0) {

TODO Auto-generated method stub

}

}

import javaawt;

import javaawtevent;

import javaxswing;

import javatextDateFormat;

import javaxswingevent;

import javaxswingtable;

import javaxswingtree;

import javaxswingfilechooser;

import javaio;

import javautil;

public class WinExplorer extends JFrame implements TreeSelectionListener{

JPanel contentPane=(JPanel)getContentPane();;

JMenuBar menuBar = new JMenuBar();

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

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

JToolBar toolBar = new JToolBar();

JButton bttUp = new JButton();

Icon iconUp=UIManagergetIcon("FileChooserupFolderIcon");

JLabel statusBar = new JLabel();

DetailTable detailTable = new DetailTable();

JScrollPane sp = new JScrollPane(detailTable);

JSplitPane split = new JSplitPane();

FileSystemView fileSystemView=FileSystemViewgetFileSystemView();

FileNode root=new FileNode(fileSystemViewgetRoots()[0]);

DefaultTreeModel treeModel=new DefaultTreeModel(root);

JTree tree = new JTree(treeModel);

public static void main(String argv[]){

try {

UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName());

Font font=new Font("宋体",FontPLAIN,12);

String names[]={"Label","CheckBox","PopupMenu","TextPane",

"MenuItem","CheckBoxMenuItem","JRadioButtonMenuItem",

"ComboBox","Button","Tree","ScrollPane","TabbedPane",

"EditorPane","TitledBorder","Menu","TextArea","OptionPane",

"MenuBar","ToolBar","ToggleButton","ToolTip","ProgressBar",

"TableHeader","Panel","List","ColorChooser","PasswordField",

"TextField","Table","Label","Viewport","RadioButtonMenuItem",

"RadioButton"};

for(int i=0;i<nameslength;i++)UIManagerput(names[i]+"font",font);

UIManagerput("Labelforeground",Colorblack);

UIManagerput("Borderforeground",Colorblack);

UIManagerput("TitledBordertitleColor",Colorblack);

new WinExplorer()show();

}catch(Exception e){

eprintStackTrace();

}

}

public WinExplorer() {

contentPanesetLayout(new BorderLayout());

Dimension dimension = getToolkit()getScreenSize();

int i = (dimensionwidth - 640) / 2;

int j = (dimensionheight - 480) / 2;

setBounds(i,j,640,480);

setTitle("资源管理器");

setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

setJMenuBar(menuBar);

statusBarsetText(" ");

menuItemExitaddActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {Systemexit(0);}

});

bttUpsetIcon(iconUp);

bttUpaddActionListener(new javaawteventActionListener() {

public void actionPerformed(ActionEvent e) {

try{

TreePath upPath=treegetSelectionPath()getParentPath();

if(upPath!=null){

treesetSelectionPath(upPath);

treescrollPathToVisible(upPath);

}

}catch(Exception ex){}

}

});

splitsetDividerSize(6);

splitsetLeftComponent(new JScrollPane(tree));

splitsetRightComponent(sp);

splitsetDividerLocation(180);

spgetViewport()setBackground(Colorwhite);

menuFileadd(menuItemExit);

menuBaradd(menuFile);

contentPaneadd(toolBar, BorderLayoutNORTH);

toolBaradd(bttUp, null);

contentPaneadd(statusBar, BorderLayoutSOUTH);

contentPaneadd(split, BorderLayoutCENTER);

treeaddTreeExpansionListener(new MyExpandsionListener());

treesetCellRenderer(new MyTreeCellRenderer());

treeaddTreeSelectionListener(this);

treesetSelectionRow(0);

treesetComponentOrientation(ComponentOrientationUNKNOWN);

}

public void valueChanged(TreeSelectionEvent e){

Object obj=treegetLastSelectedPathComponent();

if(obj==null)return;

else detailTablesetParent(((FileNode)obj)getFile());

}

class MyTreeCellRenderer extends DefaultTreeCellRenderer {

public MyTreeCellRenderer() {}

public Component getTreeCellRendererComponent(JTree tree,Object value,

boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus) {

supergetTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);

setIcon(fileSystemViewgetSystemIcon(((FileNode)value)getFile()));

return this;

}

}

class MyExpandsionListener implements TreeExpansionListener {

public MyExpandsionListener() {}

public void treeExpanded(TreeExpansionEvent event) {

if(eventgetPath() == null){

return;

}

treesetCursor(new Cursor(CursorWAIT_CURSOR));

TreePath path = eventgetPath();

FileNode node = (FileNode)pathgetLastPathComponent();

nodeexplore();

treeModelnodeStructureChanged(node);

treesetCursor(new Cursor(CursorDEFAULT_CURSOR));

}

public void treeCollapsed(TreeExpansionEvent event) {}

}

class FileNode extends DefaultMutableTreeNode {

private boolean explored = false;

public FileNode(File file) { setUserObject(file); }

public boolean getAllowsChildren() { return isDirectory(); }

public boolean isLeaf() { return !isDirectory();}

public File getFile() { return (File)getUserObject(); }

public boolean isExplored() { return explored; }

public void setExplored(boolean b){ explored=b;}

public boolean isDirectory() { return getFile()isDirectory();}

public String toString() {

File file = (File)getUserObject();

String filename = filetoString();

int index = filenamelastIndexOf(Fileseparator);

return (index != -1 && index != filenamelength()-1)

filenamesubstring(index+1) : filename;

}

public void explore() {

if(!isExplored()) {

File file = getFile();

File[] children = filelistFiles();

if(children==null||childrenlength==0)return;

for(int i=0; i < childrenlength; ++i)

{

File f=children[i];

if(fisDirectory())add(new FileNode(children[i]));

}

explored = true;

}

}

}

class DetailTable extends JTable{

DetailTableModel model=new DetailTableModel();

public DetailTable(){

setModel(model);

setShowGrid(false);

TableColumnModel colModel = getColumnModel();

for (int i=0;i<3;i++)

colModelgetColumn(i)setCellRenderer(new DetailsTableCellRenderer());

setRowHeight(18);

thisaddMouseListener(new MouseAdapter(){

public void mouseClicked(MouseEvent e) {

if(egetClickCount()==2){

for (int i = 0; i <getRowCount(); i++) {

if(getCellRect(i,0,true)contains(egetPoint())){

openSelect();

break;

}

}

}

}

});

}

public void openSelect(){

Object obj=modelgetValueAt(getSelectedRow(),0);

if(obj==null)return;

File f=(File)obj;

if(fisDirectory()){

//expand tree

}else{

//open select file

}

}

public void setParent(File parent){

modelremoveAllRows();

File list[]=parentlistFiles();

if(list==null)return;

Vector vDir=new Vector(),vFile=new Vector();

for (int i = 0; i < listlength; i++) {

if(list[i]isDirectory())vDiradd(list[i]);

else vFileadd(list[i]);

}

sortElements(vFile);

sortElements(vDir);

for (int i = 0; i < vDirsize(); i++)modeladdFile((File)vDirelementAt(i));

for (int i = 0; i < vFilesize(); i++)modeladdFile((File)vFileelementAt(i));

}

public void sortElements(Vector v)

{

for(int i=0;i<vsize();i++)

{

int k=i;

for(int j=i+1;j<vsize();j++){

File fa=(File)velementAt(j);

File fb=(File)velementAt(k);

if(fileSystemViewgetSystemDisplayName(fa)toLowerCase()compareTo(

fileSystemViewgetSystemDisplayName(fb)toLowerCase())<0)k=j;

}

if(k!=i)swap(k,i,v);

}

}

private void swap(int loc1,int loc2,Vector v){

Object tmp=velementAt(loc1);

vsetElementAt(velementAt(loc2),loc1);

vsetElementAt(tmp,loc2);

}

class DetailTableModel extends DefaultTableModel {

public DetailTableModel() {

addColumn("名称");

addColumn("大小");

addColumn("修改时间");

}

public void addFile(File f){

addRow(new Object[]{f,new Double(flength()/1024),

new javasqlDate(flastModified())});

}

public void removeAllRows(){

while(getRowCount()!=0) removeRow(0);

}

public boolean isCellEditable(int row, int column) {return false;}

}

class DetailsTableCellRenderer extends DefaultTableCellRenderer {

DetailsTableCellRenderer() {}

public Component getTableCellRendererComponent(JTable table, Object value,

boolean isSelected, boolean hasFocus, int row, int column) {

if (column == 1){

setHorizontalAlignment(SwingConstantsTRAILING);

isSelected=hasFocus=false;

}else if(column==2){

setHorizontalAlignment(SwingConstantsCENTER);

isSelected=hasFocus=false;

}else setHorizontalAlignment(SwingConstantsLEADING);

return supergetTableCellRendererComponent(

table, value, isSelected, hasFocus, row, column);

}

public void setValue(Object value) {

setIcon(null);

if (value instanceof File) {

File file = (File)value;

setText(fileSystemViewgetSystemDisplayName(file));

setIcon(fileSystemViewgetSystemIcon(file));

}else{

supersetValue(value);

}

}

}

}

}

你双击左面的桌面图标就可以浏览了,别双击字。

public class RandomNum

{

public static void main(String[] args)

{

int num=(int)(Mathrandom()800);//取800以内随机数

Systemoutprintln("所取随机数为:"+num);

Systemoutprintln("它的百位数字为:"+(num/100));//取百位

Systemoutprintln("它的十位数字为:"+((num-(num/100)100))/10);//取十位

Systemoutprintln("它的十位数字为:"+(num%10));//取个位

}

}

abstract class VirtualLife{

int lifeValue;

int attackPowe;

int describe;

public abstract void physicalAttack();

}

abstract class VirtualHero extends VirtualLife{

int defense;

int armor;

}

interface ISkill{

void skillFirst();

void skillSecond();

void skillThird();

void skillFourth();

}

class Ezreal extends VirtualHero implements ISkill{

String hero ="Ezreal";

public void physicalAttack() {

Systemoutprintln(hero+"物理攻击为"+attackPowe);

}

public void skillFirst() {

Systemoutprintln(hero+"使用了技能"+1);

}

public void skillSecond() {

Systemoutprintln(hero+"使用了技能"+2);

}

public void skillThird() {

Systemoutprintln(hero+"使用了技能"+3);

}

public void skillFourth() {

Systemoutprintln(hero+"使用了技能"+4);

}

}

class Annie extends VirtualHero implements ISkill{

String hero ="Annie";

public void physicalAttack() {

Systemoutprintln(hero+"物理攻击为"+attackPowe);

}

public void skillFirst() {

Systemoutprintln(hero+"使用了技能"+1);

}

public void skillSecond() {

Systemoutprintln(hero+"使用了技能"+2);

}

public void skillThird() {

Systemoutprintln(hero+"使用了技能"+3);

}

public void skillFourth() {

Systemoutprintln(hero+"使用了技能"+4);

}

}

class Soliders extends VirtualLife{

public void physicalAttack() {

Systemoutprintln("我是小兵,我的攻击力为"+attackPowe);

}

}

public class Test {

public static void main(String[] args){

Ezreal ezreal=new Ezreal();

ezrealattackPowe=10;

ezrealphysicalAttack();

Annie annie=new Annie();

annieattackPowe=20;

anniephysicalAttack();

Soliders solider=new Soliders();

soliderattackPowe=5;

soliderphysicalAttack();

}

}

以上就是关于求助:JAVA小程序全部的内容,包括:求助:JAVA小程序、急需一段java小程序、编写一个java的应用小程序。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10638592.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-10
下一篇2023-05-10

发表评论

登录后才能评论

评论列表(0条)

    保存