网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

大一java源代码 大一java编程题

JAVA记事本的源代码

我给你如下:/*

成都创新互联公司长期为1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为西夏企业提供专业的成都网站设计、做网站西夏网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。

* WriteBoard.java

*

* Created on 2006年12月19日, 下午7:26

*/

/**

*

* @author LecH.giF

*/

import java.awt.datatransfer.*;

import java.awt.event.*;

import java.awt.*;

import java.io.*;

import java.awt.FileDialog;

public class WriteBoard extends java.awt.Frame {

Clipboard clipboard =null;

FileDialog fc = new FileDialog(this);

/** Creates new form WriteBoard */

public WriteBoard() {

clipboard = getToolkit().getSystemClipboard();

initComponents();

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// editor-fold defaultstate="collapsed" desc=" Generated Code "

private void initComponents() {

textArea1 = new java.awt.TextArea();

menuBar1 = new java.awt.MenuBar();

menu1 = new java.awt.Menu();

menuItem1 = new java.awt.MenuItem();

menuItem2 = new java.awt.MenuItem();

menuItem3 = new java.awt.MenuItem();

menuItem4 = new java.awt.MenuItem();

menuItem5 = new java.awt.MenuItem();

menu2 = new java.awt.Menu();

menuItem6 = new java.awt.MenuItem();

menuItem7 = new java.awt.MenuItem();

menuItem8 = new java.awt.MenuItem();

setTitle("WriteBoard");

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

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

exitForm(evt);

}

});

add(textArea1, java.awt.BorderLayout.CENTER);

menu1.setLabel("Menu");

menuItem1.setLabel("\u65b0\u5efa");

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

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

newText(evt);

}

});

menu1.add(menuItem1);

menuItem2.setLabel("\u6253\u5f00");

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

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

open(evt);

}

});

menu1.add(menuItem2);

menuItem3.setLabel("\u4fdd\u5b58");

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

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

menuItem3ActionPerformed(evt);

}

});

menu1.add(menuItem3);

menuItem4.setLabel("\u53e6\u5b58\u4e3a");

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

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

menuItem4ActionPerformed(evt);

}

});

menu1.add(menuItem4);

menuItem5.setLabel("\u9000\u51fa");

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

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

exit(evt);

}

});

menu1.add(menuItem5);

menuBar1.add(menu1);

menu2.setLabel("\u7f16\u8f91");

menuItem6.setLabel("\u526a\u5207");

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

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

menuItem6ActionPerformed(evt);

}

});

menu2.add(menuItem6);

menuItem7.setLabel("\u590d\u5236");

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

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

menuItem7ActionPerformed(evt);

}

});

menu2.add(menuItem7);

menuItem8.setLabel("\u7c98\u8d34");

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

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

menuItem8ActionPerformed(evt);

}

});

menu2.add(menuItem8);

menuBar1.add(menu2);

setMenuBar(menuBar1);

pack();

}// /editor-fold

private void menuItem4ActionPerformed(java.awt.event.ActionEvent evt) {

fc.show();

if(fc.getFile()!=null){

File file = new File(fc.getFile());

try {

PrintWriter pw = new PrintWriter(file);

pw.print(textArea1.getText());

pw.flush();

pw.close();

} catch (FileNotFoundException ex) {

ex.printStackTrace();

}

}

else{

return;

}

}

private void menuItem3ActionPerformed(java.awt.event.ActionEvent evt) {

fc.show();

if(fc.getFile()!=null){

File file = new File(fc.getFile());

try {

PrintWriter pw = new PrintWriter(file);

pw.print(textArea1.getText());

pw.flush();

pw.close();

} catch (FileNotFoundException ex) {

ex.printStackTrace();

}

}

else{

return;

}

}

private void menuItem8ActionPerformed(java.awt.event.ActionEvent evt) {

Transferable contents = clipboard.getContents(this);

DataFlavor flavor = DataFlavor.stringFlavor;

if(contents.isDataFlavorSupported(flavor))

try{

String str;

str=(String)contents.getTransferData(flavor);

textArea1.append(str);

}catch(Exception e){}

}

private void menuItem7ActionPerformed(java.awt.event.ActionEvent evt) {

String temp = this.textArea1.getSelectedText();

StringSelection text = new StringSelection(temp);

clipboard.setContents(text,null);

}

private void menuItem6ActionPerformed(java.awt.event.ActionEvent evt) {

String temp = this.textArea1.getSelectedText();

StringSelection text = new StringSelection(temp);

clipboard.setContents(text,null);

int start = textArea1.getSelectionStart();

int end = textArea1.getSelectionEnd();

textArea1.replaceRange("",start,end);

}

private void open(java.awt.event.ActionEvent evt) {

fc.show();

if(fc.getFile()!=null){

File file = new File(fc.getFile());

try {

FileReader fr = new FileReader(file);

BufferedReader br = new BufferedReader(fr);

String s;

try {

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

textArea1.append(s+"\n");

}

fr.close();

br.close();

} catch (IOException ex) {

ex.printStackTrace();

}

} catch (FileNotFoundException ex) {

ex.printStackTrace();

}

}

else{

return;

}

}

private void newText(java.awt.event.ActionEvent evt) {

this.textArea1.setText("");

}

private void exit(java.awt.event.ActionEvent evt) {

System.exit(0);

}

/** Exit the Application */

private void exitForm(java.awt.event.WindowEvent evt) {

System.exit(0);

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new WriteBoard().setVisible(true);

}

});

}

// Variables declaration - do not modify

private java.awt.Menu menu1;

private java.awt.Menu menu2;

private java.awt.MenuBar menuBar1;

private java.awt.MenuItem menuItem1;

private java.awt.MenuItem menuItem2;

private java.awt.MenuItem menuItem3;

private java.awt.MenuItem menuItem4;

private java.awt.MenuItem menuItem5;

private java.awt.MenuItem menuItem6;

private java.awt.MenuItem menuItem7;

private java.awt.MenuItem menuItem8;

private java.awt.TextArea textArea1;

// End of variables declaration

}

java 源代码注释

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

public class GameTest extends JFrame implements ActionListener{

/*

* 新建一个主面板(这个类可能是自定义的,本程序和API中没有)。

*/

MainPanel j=new MainPanel();

JButton jPreview;

JLabel label;

Container container;

JPanel panel;

/**

* 主函数

* @param args

*/

public static void main(String[] args) {

//运行程序

new GameTest();

}

/**

* 构造函数。

*

*/

public GameTest()

{

//新建一个标题为“拼图”的窗口

JFrame fr =new JFrame("拼图");

//获取窗口容器。

container=fr.getContentPane();

//创建菜单条

JMenuBar jMenuBar=new JMenuBar();

//以下初始化菜单,并且设置快捷键和添加监听器。

JMenu jMenuGame=new JMenu("游戏(G)");

jMenuGame.setMnemonic('g');

JMenuItem jMenuItemStart = new JMenuItem("开始(S)");

jMenuItemStart.setMnemonic('s');

jMenuItemStart.addActionListener(this);

JMenuItem jMenuItemExit=new JMenuItem("退出(E)");

jMenuItemExit.setMnemonic('e');

jMenuItemExit.addActionListener(this);

jMenuGame.add(jMenuItemStart);

jMenuGame.add(jMenuItemExit);

//初始化按钮并设置快捷键和添加监听器

JButton jChoice=new JButton("选图(X)");

jChoice.setMnemonic('x');

jChoice.addActionListener(this);

jPreview=new JButton("预览(P)");

jPreview.setMnemonic('p');

jPreview.addActionListener(this);

//将菜单和按钮添加到菜单条中

jMenuBar.add(jMenuGame);

jMenuBar.add(jChoice);

jMenuBar.add(jPreview);

//将菜单条设为该窗口的主菜单

fr.setJMenuBar(jMenuBar);

//将主面板添加到该窗口的容器中。

container.add(j);

//设置大小

fr.setSize(315,360 );

fr.setVisible(true);

//设置默认关闭方式。

fr.setDefaultCloseOperation(3);

}

/**

* 事件处理函数。

*/

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand()=="开始(S)")

{

j.Start();

}

if(e.getActionCommand()=="预览(P)")

{

j.setVisible(false);

panel=new JPanel();

Icon icon=new ImageIcon("pictrue/pic"+"_"+MainPanel.pictureID+".jpg");

label=new JLabel(icon);

label.setBounds(300, 300, 0, 0);

panel.add(label);

panel.setSize(300, 300);

panel.setVisible(true);

this.container.add(panel);

jPreview.setText("返回(P)");

}

if(e.getActionCommand()=="返回(P)")

{

panel.setVisible(false);

j.setVisible(true);

j.repaint();

jPreview.setText("预览(P)");

}

if(e.getActionCommand()=="退出(E)")

{

System.exit(0);

}

if(e.getActionCommand()=="选图(X)")

{

//初始化选择框,并提供选择。

Choice pic = new Choice();

pic.add("七里香");

pic.add("依然范特西");

pic.add("八度空间");

pic.add("十一月的肖邦");

pic.add("魔杰座");

pic.add("叶惠美");

pic.add("我很忙");

int i=JOptionPane.showConfirmDialog(this, pic, "选择图片", JOptionPane.OK_CANCEL_OPTION);

if(i==JOptionPane.YES_OPTION)

{

//选择图片

MainPanel.pictureID=pic.getSelectedIndex()+1;

j.removeAll();

j.reLoadPicture();

j.repaint();

}

}

}

}

Java大一的题目求大神帮忙看看怎么写TAT求源代码

哈哈~网上很多哈,GUI我也不会,现学现卖一个

package swing;

import javafx.embed.swing.JFXPanel;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.text.DateFormat;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

/**

* @author wenxy

* @create 2020-05-01

*/

public class JavaFxDate {

public static void main(String[] args) {

// 创建 JFrame 实例

JFrame frame = new JFrame();

// Setting the width and height of frame

frame.setSize(310, 180);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/* 创建面板,这个类似于 HTML 的 div 标签

* 我们可以创建多个面板并在 JFrame 中指定位置

* 面板中我们可以添加文本字段,按钮及其他组件。

*/

JPanel panel = new JPanel();

// 添加面板

frame.add(panel);

/*

* 调用用户定义的方法并添加组件到面板

*/

placeComponents(panel);

// 设置界面可见

frame.setVisible(true);

}

private static void placeComponents(JPanel panel) {

/* 布局部分我们这边不多做介绍

* 这边设置布局为 null

*/

panel.setLayout(null);

// 创建 JLabel

JLabel userLabel = new JLabel("请输入日期字符串");

userLabel.setBounds(5, 5, 300, 25);

panel.add(userLabel);

/*

* 创建文本域用于用户输入

*/

JTextField userText = new JTextField(20);

userText.setBounds(5, 40, 200, 25);

panel.add(userText);

// 创建 JLabel

JLabel showLable = new JLabel();

showLable.setBounds(5, 70, 300, 25);

panel.add(showLable);

// 创建登录按钮

JButton loginButton = new JButton("转换");

loginButton.setBounds(180, 40, 100, 25);

loginButton.addActionListener(new ActionListener() {

DateFormat input = new SimpleDateFormat("yyyy-MM-dd");

DateFormat output = new SimpleDateFormat("yyyy年MM月dd日");

{

input.setLenient(false);    // 设置严格按格式匹配

output.setLenient(false);

}

@Override

public void actionPerformed(ActionEvent actionEvent) {

try {

Date date = convert(userText.getText());

showLable.setText("成功:" + output.format(date));

showLable.setForeground(Color.GREEN);

} catch (WrongDateException e) {

showLable.setText(e.getMessage());

showLable.setForeground(Color.RED);

}

}

private Date convert(String text) throws WrongDateException {

try {

return input.parse(text);

} catch (ParseException e) {

throw new WrongDateException(text);

}

}

});

panel.add(loginButton);

}

static class WrongDateException extends Exception {

WrongDateException(String s) {

super(s + "不是合法的日期字符串");

}

}

}


网站栏目:大一java源代码 大一java编程题
文章转载:http://bjjierui.cn/article/hpdgsi.html

其他资讯