求助:JAVA小程序

Python035

求助:JAVA小程序,第1张

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

问题描述:

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

解析:

import java.io.*

import java.util.Calendar

import java.awt.*

import java.awt.event.*

import javax.swing.*

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

Container c = this.getContentPane()

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(){

this.addWindowListener(this)

c.setLayout(new BorderLayout())

c.add(jmb,BorderLayout.NORTH)

this.setTitle("新建 文本文档")

jmb.add(jm1)

jm1.setMnemonic('f')

jm1.addActionListener(this)

jmb.add(jm2)

jm2.setMnemonic('e')

jmb.add(jm3)

jm3.setMnemonic('o')

jmb.add(jm4)

jm4.setMnemonic('v')

jmb.add(jm5)

jm5.setMnemonic('h')

jm1.add(jmi1)

jmi1.addActionListener(this)

jmi1.setAccelerator(KeyStroke.getKeyStroke('N',Event.CTRL_MASK,false))

jm1.addSeparator()

jm1.add(jmi2)

jmi2.setAccelerator(KeyStroke.getKeyStroke('O',Event.CTRL_MASK,false))

jmi2.addActionListener(this)

jm1.addSeparator()

jm1.add(jmi3)

jmi3.setAccelerator(KeyStroke.getKeyStroke('S',Event.CTRL_MASK,false))

jmi3.addActionListener(this)

jm1.addSeparator()

jm1.add(jmi4)

jmi1.setMnemonic('n')

jmi2.setMnemonic('o')

jmi3.setMnemonic('s')

jmi4.setMnemonic('x')

jmi4.addActionListener(this)

jm2.add(jmi5)

jm2.addSeparator()

jm2.add(jmi6)

jm2.addSeparator()

jm2.add(jmi7)

jm2.addSeparator()

jm2.add(jmi8)

jm2.add(jmi12)

jmi12.addActionListener(this)

jm3.add(jcbmi)

jcbmi.addItemListener(this)

jm3.addSeparator()

jm3.add(jmi9)

jm4.add(jmi10)

jmi10.addActionListener(this)

jm5.add(jmi11)

jmi11.addActionListener(this)

c.add(jsp)

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)

this.setSize(500,500)

this.setVisible(true)

}

public void actionPerformed(ActionEvent e){

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

jta.setText("")

this.setTitle("无标题 - 记事本")

}

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

File f1

JFileChooser jfc1 = new JFileChooser()

int num1 = jfc1.showOpenDialog(this)

if(num1==JFileChooser.APPROVE_OPTION){

try{

f1 = jfc1.getSelectedFile()

this.setTitle(f1.getName())

FileReader fr = new FileReader(f1)

BufferedReader br = new BufferedReader(fr)

String str

while((str = br.readLine())!=null){

jta.setText(str)

}

fr.close()

br.close()

}catch(FileNotFoundException e1){

e1.printStackTrace()

}catch(IOException e2){

e2.printStackTrace()

}

}

}

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

File f2 = null

JFileChooser jfc2 = new JFileChooser()

int num2 = jfc2.showSaveDialog(this)

if(num2==JFileChooser.APPROVE_OPTION){

f2=jfc2.getSelectedFile()

this.setTitle(f2.getName())

try{

FileWriter fw = new FileWriter(f2)

BufferedWriter bw = new BufferedWriter(fw)

bw.write(jta.getText())

bw.close()

fw.close()

}catch(IOException e2){

e2.printStackTrace()

}

}

}

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

int a = JOptionPane.showConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION)

if(a==1){

this.dispose()

}else if(a==0){

File f2 = null

JFileChooser jfc2 = new JFileChooser()

int num2 = jfc2.showSaveDialog(this)

if(num2==JFileChooser.APPROVE_OPTION){

f2=jfc2.getSelectedFile()

this.setTitle(f2.getName())

try{

FileWriter fw = new FileWriter(f2)

BufferedWriter bw = new BufferedWriter(fw)

bw.write(jta.getText())

bw.close()

fw.close()

}catch(IOException e2){

e2.printStackTrace()

}

this.dispose()

}

}

}

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

Calendar c1 =Calendar.getInstance()

int y = c1.get(Calendar.YEAR)

int m = c1.get(Calendar.MONTH)

int d = c1.get(Calendar.DATE)

int h = c1.get(Calendar.HOUR)

int m1 = c1.get(Calendar.MINUTE)

int m2 = m+1

jta.setText(y+"年"+m2+"月"+d+"日"+h+":"+m1)

}

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

Color ccc = JColorChooser.showDialog(this,"color",Color.BLACK)

jta.setSelectedTextColor(ccc)

jta.setBackground(ccc)

}

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

jta.replaceRange("",jta.getSelectionStart(),jta.getSelectionEnd())

}

}

public void itemStateChanged(ItemEvent e2){

if(e2.getItemSelectable()==jcbmi){

jta.setLineWrap(true)

}else

jta.setLineWrap(false)

}

public static void main(String[] args){

new NoteBook()

}

public void windowOpened(WindowEvent arg0) {

}

public void windowClosing(WindowEvent arg0) {

int a = JOptionPane.showConfirmDialog(this,"文件已被改变,是否要保存?","提示",JOptionPane.YES_NO_CANCEL_OPTION)

if(a==1){

this.dispose()

}else if(a==0){

File f2 = null

JFileChooser jfc2 = new JFileChooser()

int num2 = jfc2.showSaveDialog(this)

if(num2==JFileChooser.APPROVE_OPTION){

f2=jfc2.getSelectedFile()

this.setTitle(f2.getName())

try{

FileWriter fw = new FileWriter(f2)

BufferedWriter bw = new BufferedWriter(fw)

bw.write(jta.getText())

bw.close()

fw.close()

}catch(IOException e2){

e2.printStackTrace()

}

}

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

}

}

说起小程序相信大家应该都不陌生了吧。

经过长时间的推广和使用,现在大多数人都接受了小程序的使用方法。

下面我们就一起来了解一下,小程序的入口都有哪些类型的。

1社交立减金入口适用类型:需要使用微信支付的小程序入口位置:接入社交立减金的微信支付页面入口介绍:1月16日,社交立减金全面开放。

从此,用户可以从社交立减金进入小程序。

使用方法:线下门店购买后,用户通过收到的模板消息领取立减金,点击“邀请好友一起领取”将立减金分享至微信群,群友可点击领取。

领取后页面即出现小程序入口,用户进入小程序内消费。

2小程序广告入口适用类型:所有小程序广告主入口位置:小程序内广告位入口介绍:3月19日,小程序广告开放。

目前小程序支持banner广告和视频激励式广告。

这两种广告都支持跳转小程序。

3服务直达入口适用类型:服务类小程序入口位置:微信搜一搜结果页入口介绍:4月18日,微信内测服务直达功能。

用户搜一搜输入关键词后,参加服务直达的小程序则会优先显示用户面前。

服务直达功能,给了小程序一个优质的服务入口。

4App打开小程序适用类型:所有小程序入口位置:App内入口介绍:5月18日,支持App直接打开小程序。

这个功能是企业入口期待榜“前三名”,现终于实现了。

同样这也意味着,微信外部,除了小程序码、企业微信关联小程序以外,App也能直接打开小程序。

5品牌搜索入口适用类型:所有品牌小程序入口位置:微信搜一搜结果页入口介绍:7月6日,微信开放品牌搜索能力。

所有开通品牌搜索的商家将获得品牌官方区和微主页的能力:①品牌官方区,是获得认证的品牌搜索下的专属区域,用户获取品牌信息和服务的官方渠道。

②微主页,是微信提供的标准化小程序,包括品牌介绍、主营产品、服务、联系方式等模块。