Java前端实训记录day03

一.用文件实现回收浏览器上的学生信息

在浏览器上输入要保存的学生信息,显示在网页上,并回收到文件中
附源码

链接:https://pan.baidu.com/s/12_Naaz-TsYw0BWAQr-kAiQ 密码:bcl9

二.mysql数据库的学习

( 简单的使用:增删改查)

1.数据库表

数据库中以表为组织单位存储数据
表类似我们的java类,每个字段都有对应的数据类型
——>
类中属性——>表中字段
对象——>记录

2.命令行操作数据库

连接:mysql -hlocalhost -uroot -p
退出:exit或quit或/q
查看: show databases;
使用:use 数据库名;分号结尾
查看表:show tables;
查询数据:select 内容 from 表名;
创建库:create 库名(huake_db)
创建表:create table student(id int,name varchar(16),age int)charset utf8;(表名)
查看表的创建语句:show create table student;(具体表名)
查看表结构:desc student;
给表重命名:rename table student to new_student;(旧表名——新表名)
删掉数据表:drop table new_student;

3.SQL语句

SQL分类:

1.数据定义语言:

简称DDL(Data Definition Language),用来定义数据库对象:数据库、表、列等;关键字:create、alter、drop等。

2.数据操作语言:

简称DML(Data Manipulation Language),用来定义数据库库中表中的记录进行更新。关键字:insert、delete、update等。

3.数据控制语言:

简称DCL(Data Control Language),用来定义数据库的访问权限和安全级别及创建用户。

4.数据查询语言:

简称DQL(Data Query Language),用来查询数据库中表的记录,关键字:select、from、where等。

4.数据库连接指令

类似命令行

5.一个简单的JDBC案例,实现了java驱动数据库,然后实现学生信息的读取。

附工程源码
链接:https://pan.baidu.com/s/1CPCKiM6UIyDtmBofuXCUrw 密码:tvtt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的 Java 前端界面展示一周时间段选择的示例代码: ```java import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.Calendar; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; public class WeekdayPicker extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; private static final String[] WEEKDAYS = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; private static final String[] MONTHS = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; private JButton[] dayButtons; private JLabel monthLabel; private JLabel yearLabel; private Calendar currentCalendar; public WeekdayPicker() { super("WeekdayPicker"); currentCalendar = Calendar.getInstance(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(new Dimension(400, 300)); setLocationRelativeTo(null); setResizable(false); setLayout(new BorderLayout()); initUI(); setVisible(true); } private void initUI() { JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton prevYearButton = new JButton("<<"); prevYearButton.setActionCommand("prevYear"); prevYearButton.addActionListener(this); topPanel.add(prevYearButton); JButton prevMonthButton = new JButton("<"); prevMonthButton.setActionCommand("prevMonth"); prevMonthButton.addActionListener(this); topPanel.add(prevMonthButton); monthLabel = new JLabel(getMonthString(currentCalendar.get(Calendar.MONTH)), SwingConstants.CENTER); monthLabel.setFont(new Font("Arial", Font.BOLD, 18)); monthLabel.setPreferredSize(new Dimension(120, 30)); topPanel.add(monthLabel); yearLabel = new JLabel(String.valueOf(currentCalendar.get(Calendar.YEAR)), SwingConstants.CENTER); yearLabel.setFont(new Font("Arial", Font.BOLD, 18)); yearLabel.setPreferredSize(new Dimension(60, 30)); topPanel.add(yearLabel); JButton nextMonthButton = new JButton(">"); nextMonthButton.setActionCommand("nextMonth"); nextMonthButton.addActionListener(this); topPanel.add(nextMonthButton); JButton nextYearButton = new JButton(">>"); nextYearButton.setActionCommand("nextYear"); nextYearButton.addActionListener(this); topPanel.add(nextYearButton); add(topPanel, BorderLayout.NORTH); JPanel centerPanel = new JPanel(new GridLayout(7, 7)); dayButtons = new JButton[49]; for (int i = 0; i < 7; i++) { centerPanel.add(new JLabel(WEEKDAYS[i], SwingConstants.CENTER)); } for (int i = 0; i < 49; i++) { JButton button = new JButton(); button.setPreferredSize(new Dimension(50, 50)); button.setBorder(BorderFactory.createEmptyBorder()); button.setFocusPainted(false); button.addActionListener(this); dayButtons[i] = button; centerPanel.add(button); } updateDayButtons(); add(centerPanel, BorderLayout.CENTER); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); bottomPanel.add(cancelButton); JButton okButton = new JButton("OK"); okButton.addActionListener(this); bottomPanel.add(okButton); add(bottomPanel, BorderLayout.SOUTH); } private void updateDayButtons() { int year = currentCalendar.get(Calendar.YEAR); int month = currentCalendar.get(Calendar.MONTH); int dayOfWeek = currentCalendar.get(Calendar.DAY_OF_WEEK); int firstDayOfWeek = currentCalendar.getFirstDayOfWeek(); currentCalendar.set(Calendar.DAY_OF_MONTH, 1); int daysInMonth = currentCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); int day = 1; int i = 0; for (; i < dayOfWeek - firstDayOfWeek; i++) { dayButtons[i].setText(""); dayButtons[i].setEnabled(false); dayButtons[i].setBackground(new Color(240, 240, 240)); } for (; i < dayOfWeek - firstDayOfWeek + daysInMonth; i++) { dayButtons[i].setText(String.valueOf(day)); dayButtons[i].setEnabled(true); dayButtons[i].setBackground(new Color(255, 255, 255)); day++; } for (; i < dayButtons.length; i++) { dayButtons[i].setText(""); dayButtons[i].setEnabled(false); dayButtons[i].setBackground(new Color(240, 240, 240)); } monthLabel.setText(getMonthString(month)); yearLabel.setText(String.valueOf(year)); } private String getMonthString(int month) { return MONTHS[month]; } @Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); switch (command) { case "prevYear": currentCalendar.add(Calendar.YEAR, -1); break; case "prevMonth": currentCalendar.add(Calendar.MONTH, -1); break; case "nextMonth": currentCalendar.add(Calendar.MONTH, 1); break; case "nextYear": currentCalendar.add(Calendar.YEAR, 1); break; case "Cancel": dispose(); break; case "OK": SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); StringBuilder builder = new StringBuilder(); builder.append(sdf.format(currentCalendar.getTime())).append(" - "); currentCalendar.add(Calendar.DAY_OF_MONTH, 6); builder.append(sdf.format(currentCalendar.getTime())); System.out.println(builder.toString()); dispose(); break; default: break; } updateDayButtons(); } public static void main(String[] args) { new WeekdayPicker(); } } ``` 该示例代码实现了一个简单的一周时间段选择的功能,具体如下: 1. 界面由上、中、下三个部分组成,分别是顶部的年月选择、中间的日期选择和底部的取消和确定按钮。 2. 日期选择部分使用 GridLayout 布局方式,排列为 7 行 7 列的网格,第一行为星期几,其余行为日期。使用 JButton 实现每个日期的按钮。 3. 使用 Calendar 类获取当前年月和计算每个月的日期,并且根据日期的星期几确定在网格中的位置,更新每个日期按钮的显示文本、是否可用和背景色。 4. 点击年月选择按钮或日期按钮,更新当前年月或者选择日期,并且更新日期选择部分的显示。 5. 点击确定按钮,将选择的时间段输出到控制台,并且关闭界面。 希望这个示例代码能够对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值