求 java开发wap应用程序的教程或书
例如开发一款wap的网络游戏。越详细越好。 求教高手!QQ413205789,验证请注明:java相关 谢谢!
更新时间:2021-05-19 12:05
最满意答案
件分割合并工具的Java源码2007/02/21 05:38 A.M.public class FileCut /*cl_tl*/ { private Shell shell; private Display display; private Text txtSourceFile; private Text txtNewFilePath; private Text txtFileSize; private Button btnChooseFile; private Button btnChoosePath; private Button btnCut; private Button btnUnionFiles; private Button btnUp; private Button btnDown; private Button btnClear; private Button btnClearAll; private Button btnUnion; private Table tblFileList; private File sourceFile = null; /*源文件*/ private File[] newFile = null; /*分割后产生的文件*/ private int fileCount = 0; /*分割成的文件个数*/ private int fileSize = 0; /*分割的文件块大小*/ private String strSourceFile = null; /*源文件路径及名称*/ private String strNewFilePath = null; /*分割文件存放路径*/ public static void main(String[] args) { Display display=new Display(); FileCut Item=new FileCut(); Item.createShell(); while( !Item.shell.isDisposed()) { if(!display.readAndDispatch()) display.sleep(); } display.dispose(); } /*fn_hd *rem:创建窗体 *aut: *log:2005-11-24 */ private void createShell() /*fn_tl*/ { shell = new Shell(display, SWT.MIN); shell.setBounds(300,250,500,330); shell.setText("文件分割合并"); GridLayout shellLayout = new GridLayout(); shellLayout.numColumns = 3; shell.setLayout(shellLayout); createWidgets(); shell.open(); } /**fn_hd *rem:在窗体内添加控件 *per: *aut: *log:2005-11-24 */ private void createWidgets() /*fn_tl*/ { final Label lblNull0 = new Label(shell,SWT.None); GridData gd0 = new GridData(); gd0.horizontalSpan = 3; lblNull0.setLayoutData(gd0); final Label lblSourceFile = new Label(shell, SWT.None); lblSourceFile.setText("源 文 件"); GridData gd2 = new GridData(GridData.FILL_HORIZONTAL); txtSourceFile = new Text(shell, SWT.BORDER); txtSourceFile.setLayoutData(gd2); btnChooseFile = new Button(shell, SWT.PUSH); btnChooseFile.setText(".."); final Label lblPath = new Label(shell, SWT.None); lblPath.setText("存放路径"); txtNewFilePath = new Text(shell, SWT.BORDER); GridData gd3 = new GridData(GridData.FILL_HORIZONTAL); txtNewFilePath.setLayoutData(gd3); btnChoosePath = new Button(shell, SWT.PUSH); btnChoosePath.setText(".."); final Label lblSize = new Label(shell, SWT.None); lblSize.setText("分块大小(KB)"); txtFileSize = new Text(shell,SWT.BORDER); GridData gd7 = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); txtFileSize.setLayoutData(gd7); btnCut = new Button(shell, SWT.PUSH); GridData gd4 = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); btnCut.setLayoutData(gd4); btnCut.setText("开始分割"); final Label lbl1 = new Label(shell, SWT.None); GridData gd8 = new GridData(); gd8.horizontalSpan = 3; lbl1.setLayoutData(gd8); lbl1.setText("待合并的文件列表"); tblFileList = new Table(shell, SWT.BORDER); GridData gd1 = new GridData(GridData.FILL_BOTH); gd1.horizontalSpan = 2; tblFileList.setLayoutData(gd1); Composite com = new Composite(shell, SWT.None); GridLayout comLayout = new GridLayout(); com.setLayout(comLayout); final Label lblNote = new Label(shell, SWT.None); GridData data = new GridData(); data.horizontalSpan=3; lblNote.setLayoutData(data); lblNote.setText("提示:注意合并文件的顺序"); btnUnionFiles = new Button(com, SWT.PUSH); btnUnionFiles.setText("选择文件"); btnUp = new Button(com, SWT.PUSH); btnUp.setText(" 上移 "); btnUp.setEnabled(false); btnDown = new Button(com, SWT.PUSH); btnDown.setText(" 下移 "); btnDown.setEnabled(false); btnClear = new Button(com, SWT.PUSH); btnClear.setText(" 删除 "); btnClear.setEnabled(false); btnClearAll = new Button(com, SWT.PUSH); btnClearAll.setText("清空列表"); btnUnion = new Button(com, SWT.PUSH); btnUnion.setText("开始合并"); btnCut.addSelectionListener(new SelectionAdapter() //添加"开始分割"监视器 { public void widgetSelected(SelectionEvent event) { cutButtonEvent(); } }); btnChooseFile.addSelectionListener(new SelectionAdapter() //添加选择(源文件)监视器 { public void widgetSelected(SelectionEvent event) { FileDialog fdOpen = new FileDialog(shell,SWT.OPEN); String strFileName = fdOpen.open(); if (strFileName != null) { txtSourceFile.setText(strFileName); txtNewFilePath.setText(fdOpen.getFilterPath()); txtFileSize.setFocus(); } } }); btnChoosePath.addSelectionListener(new SelectionAdapter() //添加选择(分割文件存放路径)监视器 { public void widgetSelected(SelectionEvent event) { DirectoryDialog dirDia = new DirectoryDialog(shell); String strFileDir = dirDia.open(); if (strFileDir != null) { txtNewFilePath.setText(strFileDir); txtFileSize.setFocus(); } } }); btnUp.addSelectionListener(new SelectionAdapter() //添加"上移"监视器 { public void widgetSelected(SelectionEvent event) { //int[] itemIndices = tblFileList.getSelectionIndices(); int itemIndex = tblFileList.getSelectionIndex(); if (itemIndex == 0) { tblFileList.setFocus(); return; } //交换列表中两行的内容 String strTemp = tblFileList.getItem(itemIndex).getText(); tblFileList.getItem(itemIndex).setText(tblFileList.getItem( itemIndex - 1).getText()); tblFileList.getItem(itemIndex - 1).setText(strTemp); //设置焦点 tblFileList.setSelection(itemIndex - 1); tblFileList.setFocus(); } }); btnDown.addSelectionListener(new SelectionAdapter() //添加"下移"监视器 { public void widgetSelected(SelectionEvent event) { //int[] itemIndices = tblFileList.getSelectionIndices(); int itemIndex = tblFileList.getSelectionIndex(); if (itemIndex == tblFileList.getItemCount() - 1) { tblFileList.setFocus(); return; } //交换列表中两行的内容 String strTemp = tblFileList.getItem(itemIndex).getText(); tblFileList.getItem(itemIndex).setText(tblFileList.getItem( itemIndex + 1).getText()); tblFileList.getItem(itemIndex + 1).setText(strTemp); //设置焦点 tblFileList.setSelection(itemIndex + 1); tblFileList.setFocus(); } }); btnClear.addSelectionListener(new SelectionAdapter() //添加"删除"监视器 { public void widgetSelected(SelectionEvent event) { int itemIndex = tblFileList.getSelectionIndex(); tblFileList.remove(itemIndex); btnUp.setEnabled(false); btnDown.setEnabled(false); btnClear.setEnabled(false); } }); btnClearAll.addSelectionListener(new SelectionAdapter() //添加"清空列表"监视器 { public void widgetSelected(SelectionEvent event) { tblFileList.removeAll(); btnUp.setEnabled(false); btnDown.setEnabled(false); btnClear.setEnabled(false); } }); txtFileSize.addSelectionListener(new SelectionAdapter() //添加"分块大小"文本框中输入回车监视器 { public void widgetDefaultSelected(SelectionEvent event) { cutButtonEvent(); } }); btnUnionFiles.addSelectionListener(new SelectionAdapter() //添加"选择文件"监视器 { public void widgetSelected(SelectionEvent event) { FileDialog fd = new FileDialog(shell, SWT.MULTI); fd.setFilterExtensions(new String[]{"*.dat", "*.*"}); if (fd.open() != null) { String[] strFiles = fd.getFileNames(); String strFilePath = fd.getFilterPath(); //strUnionFilePath = new String[strFiles.length]; for(int i = 0; i < strFiles.length; i++) { //strUnionFilePath[i] = fd.getFilterPath(); TableItem item = new TableItem(tblFileList, SWT.None); item.setText(strFilePath + "\\" + strFiles[i]); } } } }); btnUnion.addSelectionListener(new SelectionAdapter() //添加"开始合并"监视器 { public void widgetSelected(SelectionEvent event) { if (tblFileList.getItemCount() == 0) { return; } switch (unionFiles()) { case 1: showMessage("成功", "合并完成!", SWT.OK | SWT.ICON_INFORMATION); tblFileList.removeAll(); btnUp.setEnabled(false); btnDown.setEnabled(false); btnClear.setEnabled(false); break; case -1: showMessage("错误", "文件不存在!", SWT.OK | SWT.ICON_ERROR); break; case -2: break; default: showMessage("错误", "有错误发生,文件合并失败!", SWT.OK | SWT.ICON_ERROR); } } }); tblFileList.addSelectionListener(new SelectionAdapter() //添加选中列表中元素监视器 { public void widgetSelected(SelectionEvent event) { btnUp.setEnabled(true); btnDown.setEnabled(true); btnClear.setEnabled(true); } }); } /**fn_hd *rem:显示消息框 *log:2005-11-24 */ private int showMessage(String strText, String strMessage, int i) {/*fn_tl*/ MessageBox msgBox = new MessageBox(shell,i); msgBox.setText(strText); msgBox.setMessage(strMessage); return msgBox.open(); } /**fn_hd *rem:点击"分割"按钮触发的事件响应 *log:2005-11-24 */ private void cutButtonEvent() /*fn_tl*/ { strSourceFile = txtSourceFile.getText().trim(); strNewFilePath = txtNewFilePath.getText().trim(); if (strSourceFile.equals("") || strNewFilePath.equals("")) { showMessage("提示", "请输入源文件和 \n\n分割文件的路径! ", SWT.OK | SWT.ICON_INFORMATION); return; } try { fileSize = Integer.parseInt(txtFileSize.getText()); fileSize *= 1024; if (fileSize <= 0) { showMessage("错误", "分块大小为正整数! ", SWT.OK | SWT.ICON_ERROR); return; } } catch(Exception e) { showMessage("错误", "请在分块大小框填入数字! ", SWT.OK | SWT.ICON_ERROR); return; } switch (cutFile()) { case 1: showMessage("提示", "分割完成! ", SWT.OK | SWT.ICON_INFORMATION); txtSourceFile.setText(""); txtNewFilePath.setText(""); txtFileSize.setText(""); break; case -1: showMessage("错误", "源文件不存在或存放路径不存在!", SWT.OK | SWT.ICON_ERROR); break; default: showMessage("未知错误", "文件分割失败! ", SWT.OK | SWT.ICON_ERROR); } } /*fn_hd *rem:文件分割实现 *per:成功返回1,文件未找到返回-1,其他情况返回0 *exp:IOException *aut: *log:2005-11-22,创建 *log:2005-11-24,修改 */ private int cutFile() /*fn_tl*/ { sourceFile = new File(strSourceFile); fileCount = (int) (sourceFile.length() / fileSize); if (sourceFile.length() % fileSize != 0) { fileCount++; } newFile = new File[fileCount]; try { int count = 0; int i = 0; byte[] bueff = new byte[fileSize]; FileOutputStream out = null; FileInputStream in = new FileInputStream(sourceFile); for (i = 0; i < newFile.length; i++) { newFile[i] = new File(strNewFilePath, i + sourceFile.getName() + ".dat"); } i = 0; while ((count = in.read(bueff,0,fileSize)) != -1) { out = new FileOutputStream(newFile[i]); out.write(bueff,0,count); out.close(); i++; } in.close(); return 1; } catch(FileNotFoundException e) { System.out.println(e); return -1; } catch(IOException e) { System.out.println(e); return 0; } } /*fn_hd *rem:文件合并的实现 *per:成功返回1,文件未找到返回-1,取消操作返回-2,其他情况返回0; *aut: *exp:FileNotFoundException,IOException *log:2005-11-28,创建 */ private int unionFiles() /*fn_tl*/ { String[] strFiles = new String[tblFileList.getItemCount()]; File[] unionFiles = new File[strFiles.length]; FileDialog fdSave = new FileDialog(shell, SWT.SAVE); String s = fdSave.open(); if (s == null) { return -2; } File outFile = new File(fdSave.getFilterPath(), fdSave.getFileName()); if (outFile.exists()) { int msg = showMessage("提示", "该文件以存在,是否替换?", SWT.YES | SWT.NO | SWT.ICON_QUESTION); if (msg == SWT.NO) { return -2; } } for(int i = 0; i < strFiles.length; i++) { strFiles[i] = tblFileList.getItem(i).getText(); } try { FileInputStream in = null; FileOutputStream out = new FileOutputStream(outFile); byte[] buff = new byte[1024]; int count; for(int i = 0; i < strFiles.length; i++) { in = new FileInputStream(strFiles[i]); while((count = in.read(buff,0,1024)) != -1) { out.write(buff,0,count); } in.close(); } out.close(); return 1; } catch(FileNotFoundException e) { System.out.println(e); return -1; } catch(IOException e) { System.out.println(e); return 0; } }
相关问答
更多-
java如何开发手机程序[2022-10-01]
一。 下载并安装java环境 jdk 1.4以后版本 大于1.4都可以。去sun的官网上下载 二。 下载并安装sun提供的专门开发手机软件的 java微型版,即j2me开发工具,又叫WTK全称(Wireless Toolkit)目前版本 WTK2.5.2 去sun的官网下载 如果只用写字板,记事本之类的开发工具的话,现在就可以开发了,运行WTK:->项目-新建项目,就会在C:\Documents and Settings\Administrator\j2mewtk\2.5.2\apps 下生成你的项目文件夹 ... -
手机 JAVA2.0能看TXT或者WORD的文件吗?[2022-05-19]
你的手机支持JAVA吗?支持的话就能看JAR的电子书啊!TXT的你在下载后要把编码改称unicode,点保存在编码那改你试试 -
(高分)怎样讲手机的几个java文件合并成一个java文件?[2021-11-27]
件分割合并工具的Java源码2007/02/21 05:38 A.M.public class FileCut /*cl_tl*/ { private Shell shell; private Display display; private Text txtSourceFile; private Text txtNewFilePath; private Text txtFileSize; private Button btnChooseFile; private Button btnChoosePath; ... -
手机JAVA怎么用[2022-09-07]
打开JAVA菜单就一个 设置跟 查找游戏 这很简单因为你手机上没有JAVA的游戏或软件(如一些播放器,词典什么的)只要到网上找个网下到JAVA的文件夹都是.rar格式的,再进入JAVA程序选择查找游戏找到后就会自动打开这游戏 ,下次就只要打开JAVA程序选择启动JAVA,然后就有你要的游戏了 -
java手机刷机怎么刷[2024-01-06]
刷机步骤: 1.首先到应用商店下载一个360Root的android应用,点击打开,按照软件提示一步步操作,就可以获得Root权限。 2.下载手机对应的rom安装包。 3.将安装包导入到手机上,系统会自动安装,这就ok了。 中间如果失败的话,有可能是因为rom版本不匹配。 -
推荐几个java手机游戏和mrp格式的游戏[好玩的]?[2022-02-16]
那要看你喜欢玩什么类型的游戏 -
怎么安装java手机游戏[2023-08-13]
1. 新买的卡,先在手机上格式你的 TF 卡:设置 ― 手机状态 ― 存储存储设备 ―卡 ― 菜单键 ― 格式,或先安装 TF 卡到手机上采取拍照,录象的方式,激活 TF 卡的文件夹。如果是已经使用的就不必了... 2.将我的电脑 ― 工具 ― 文件夹选项 ― 查看中的,隐藏文件和文件夹 ― 选显示 3.打开我的电脑 ― 工具 ― 文件夹选项 ― 查看,把 “隐藏受保护的操作系统文件”前面的勾去掉 4.然后用读卡器打开你的TF,就可以看见TF卡上的 KJAVA 了。复制游戏和软件到你TF卡的 KJAVA 目 ... -
手机JAVA的文件夹是哪个?[2024-03-09]
- - 应该是 游戏格式 你手机不支持吧