录java的简单介绍

博主:adminadmin 2023-03-18 20:52:07 517

今天给各位分享录java的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java录视频如何实现

1、每次开始录制时会调用一遍init方法,在指定目录位置形成一个没有任何大小的mp4文件。

2、之后在start方法里面会开一个线程不断的去截取当前的屏幕。

3、最后调用stop方法关闭线程的同时生成最终的录屏文件即可。

java可以做语音录音吗

可以。

需求:

1.实现可以从麦克风进行录音

2.可以停止录音

3.实现播放录音内容

4.并将所录的mp3文件全部存到F:/语音文件夹,语音的文件名以当前时间命名(java中是换算成秒),其中文件夹程序自己创建,不用担心出错

程序如下:

span style="font-size:18px;"import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.io.*;

import javax.sound.sampled.*;

public class MyRecord extends JFrame implements ActionListener{

//定义录音格式

AudioFormat af = null;

//定义目标数据行,可以从中读取音频数据,该 TargetDataLine 接口提供从目标数据行的缓冲区读取所捕获数据的方法。

TargetDataLine td = null;

//定义源数据行,源数据行是可以写入数据的数据行。它充当其混频器的源。应用程序将音频字节写入源数据行,这样可处理字节缓冲并将它们传递给混频器。

SourceDataLine sd = null;

//定义字节数组输入输出流

ByteArrayInputStream bais = null;

ByteArrayOutputStream baos = null;

//定义音频输入流

AudioInputStream ais = null;

//定义停止录音的标志,来控制录音线程的运行

Boolean stopflag = false;

//定义所需要的组件

JPanel jp1,jp2,jp3;

JLabel jl1=null;

JButton captureBtn,stopBtn,playBtn,saveBtn;

public static void main(String[] args) {

//创造一个实例

MyRecord mr = new MyRecord();

}

//构造函数

public MyRecord()

{

//组件初始化

jp1 = new JPanel();

jp2 = new JPanel();

jp3 = new JPanel();

//定义字体

Font myFont = new Font("华文新魏",Font.BOLD,30);

jl1 = new JLabel("录音机功能的实现");

jl1.setFont(myFont);

jp1.add(jl1);

captureBtn = new JButton("开始录音");

//对开始录音按钮进行注册监听

captureBtn.addActionListener(this);

captureBtn.setActionCommand("captureBtn");

//对停止录音进行注册监听

stopBtn = new JButton("停止录音");

stopBtn.addActionListener(this);

stopBtn.setActionCommand("stopBtn");

//对播放录音进行注册监听

playBtn = new JButton("播放录音");

playBtn.addActionListener(this);

playBtn.setActionCommand("playBtn");

//对保存录音进行注册监听

saveBtn = new JButton("保存录音");

saveBtn.addActionListener(this);

saveBtn.setActionCommand("saveBtn");

this.add(jp1,BorderLayout.NORTH);

this.add(jp2,BorderLayout.CENTER);

this.add(jp3,BorderLayout.SOUTH);

jp3.setLayout(null);

jp3.setLayout(new GridLayout(1, 4,10,10));

jp3.add(captureBtn);

jp3.add(stopBtn);

jp3.add(playBtn);

jp3.add(saveBtn);

//设置按钮的属性

captureBtn.setEnabled(true);

stopBtn.setEnabled(false);

playBtn.setEnabled(false);

saveBtn.setEnabled(false);

//设置窗口的属性

this.setSize(400,300);

this.setTitle("录音机");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setLocationRelativeTo(null);

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

if(e.getActionCommand().equals("captureBtn"))

{

//点击开始录音按钮后的动作

//停止按钮可以启动

captureBtn.setEnabled(false);

stopBtn.setEnabled(true);

playBtn.setEnabled(false);

saveBtn.setEnabled(false);

//调用录音的方法

capture();

}else if (e.getActionCommand().equals("stopBtn")) {

//点击停止录音按钮的动作

captureBtn.setEnabled(true);

stopBtn.setEnabled(false);

playBtn.setEnabled(true);

saveBtn.setEnabled(true);

//调用停止录音的方法

stop();

}else if(e.getActionCommand().equals("playBtn"))

{

//调用播放录音的方法

play();

}else if(e.getActionCommand().equals("saveBtn"))

{

//调用保存录音的方法

save();

}

}

//开始录音

public void capture()

{

try {

//af为AudioFormat也就是音频格式

af = getAudioFormat();

DataLine.Info info = new DataLine.Info(TargetDataLine.class,af);

td = (TargetDataLine)(AudioSystem.getLine(info));

//打开具有指定格式的行,这样可使行获得所有所需的系统资源并变得可操作。

td.open(af);

//允许某一数据行执行数据 I/O

td.start();

//创建播放录音的线程

Record record = new Record();

Thread t1 = new Thread(record);

t1.start();

} catch (LineUnavailableException ex) {

ex.printStackTrace();

return;

}

}

//停止录音

public void stop()

{

stopflag = true;

}

//播放录音

public void play()

{

//将baos中的数据转换为字节数据

byte audioData[] = baos.toByteArray();

//转换为输入流

bais = new ByteArrayInputStream(audioData);

af = getAudioFormat();

ais = new AudioInputStream(bais, af, audioData.length/af.getFrameSize());

try {

DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, af);

sd = (SourceDataLine) AudioSystem.getLine(dataLineInfo);

sd.open(af);

sd.start();

//创建播放进程

Play py = new Play();

Thread t2 = new Thread(py);

t2.start();

} catch (Exception e) {

e.printStackTrace();

}finally{

try {

//关闭流

if(ais != null)

{

ais.close();

}

if(bais != null)

{

bais.close();

}

if(baos != null)

{

baos.close();

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

//保存录音

public void save()

{

//取得录音输入流

af = getAudioFormat();

byte audioData[] = baos.toByteArray();

bais = new ByteArrayInputStream(audioData);

ais = new AudioInputStream(bais,af, audioData.length / af.getFrameSize());

//定义最终保存的文件名

File file = null;

//写入文件

try {

//以当前的时间命名录音的名字

//将录音的文件存放到F盘下语音文件夹下

File filePath = new File("F:/语音文件");

if(!filePath.exists())

{//如果文件不存在,则创建该目录

filePath.mkdir();

}

file = new File(filePath.getPath()+"/"+System.currentTimeMillis()+".mp3");

AudioSystem.write(ais, AudioFileFormat.Type.WAVE, file);

} catch (Exception e) {

e.printStackTrace();

}finally{

//关闭流

try {

if(bais != null)

{

bais.close();

}

if(ais != null)

{

ais.close();

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

//设置AudioFormat的参数

public AudioFormat getAudioFormat()

{

//下面注释部分是另外一种音频格式,两者都可以

AudioFormat.Encoding encoding = AudioFormat.Encoding.

PCM_SIGNED ;

float rate = 8000f;

int sampleSize = 16;

String signedString = "signed";

boolean bigEndian = true;

int channels = 1;

return new AudioFormat(encoding, rate, sampleSize, channels,

(sampleSize / 8) * channels, rate, bigEndian);

// //采样率是每秒播放和录制的样本数

// float sampleRate = 16000.0F;

// // 采样率8000,11025,16000,22050,44100

// //sampleSizeInBits表示每个具有此格式的声音样本中的位数

// int sampleSizeInBits = 16;

// // 8,16

// int channels = 1;

// // 单声道为1,立体声为2

// boolean signed = true;

// // true,false

// boolean bigEndian = true;

// // true,false

// return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed,bigEndian);

}

//录音类,因为要用到MyRecord类中的变量,所以将其做成内部类

class Record implements Runnable

{

//定义存放录音的字节数组,作为缓冲区

byte bts[] = new byte[10000];

//将字节数组包装到流里,最终存入到baos中

//重写run函数

public void run() {

baos = new ByteArrayOutputStream();

try {

System.out.println("ok3");

stopflag = false;

while(stopflag != true)

{

//当停止录音没按下时,该线程一直执行

//从数据行的输入缓冲区读取音频数据。

//要读取bts.length长度的字节,cnt 是实际读取的字节数

int cnt = td.read(bts, 0, bts.length);

if(cnt 0)

{

baos.write(bts, 0, cnt);

}

}

} catch (Exception e) {

e.printStackTrace();

}finally{

try {

//关闭打开的字节数组流

if(baos != null)

{

baos.close();

}

} catch (IOException e) {

e.printStackTrace();

}finally{

td.drain();

td.close();

}

}

}

}

//播放类,同样也做成内部类

class Play implements Runnable

{

//播放baos中的数据即可

public void run() {

byte bts[] = new byte[10000];

try {

int cnt;

//读取数据到缓存数据

while ((cnt = ais.read(bts, 0, bts.length)) != -1)

{

if (cnt 0)

{

//写入缓存数据

//将音频数据写入到混频器

sd.write(bts, 0, cnt);

}

}

} catch (Exception e) {

e.printStackTrace();

}finally{

sd.drain();

sd.close();

}

}

}

}/span

JAVA通讯录 求一个JAVA编写的通讯录,基本的就可以。

具体方法如下:

1、定义封装一条记录的实体类

2、根据实际系统容量,定义一个数组

3、完成系统中显示全部记录的逻辑

4、完成系统中添加一条记录的逻辑

5、完成系统中删除一条记录的逻辑

6、完成系统中修改一条记录的逻辑

7、全部代码:

import java.util.Scanner;

class Contact {

String cellPhone;

String name;

}

public class Main {

private static void menu () {

System.out.println("************** 菜单 ******"

+ "************");

System.out.println(" 1.显示全部通讯录");

System.out.println(" 2.增加一条记录");

System.out.println(" 3.删除一条记录");

System.out.println(" 4.修改一条记录");

System.out.println(" 0.退出");

}

public static void main(String[] args) {

Scanner scn = new Scanner(System.in);

Contact[] contacts = new Contact[200];

int size = 0;

String cmd = "";

do {

menu();

System.out.print("请输入你得选择:(0-4)");

cmd = scn.nextLine();

if (cmd.equals("1")) {

if (size == 0)

System.out.println("系统当前无记录!");

else

for (int i = 0; i size; i++) {

System.out.println(contacts[i].name + ":"

+ contacts[i].cellPhone);

}

} else if (cmd.equals("2")) {

System.out.print("请输入手机号:");

String cellphone = scn.nextLine();

System.out.print("请输入姓名:");

String name = scn.nextLine();

Contact contact = new Contact();

contact.cellPhone = cellphone;

contact.name = name;

if (size contacts.length) {

contacts[size++] = contact;

System.out.println("添加成功!");

} else {

System.out.println("你最多只能添加" +

contacts.length + "条记录");

}

} else if (cmd.equals("3")) {

System.out.print("请输入要删除的手机号:");

String cellphone = scn.nextLine();

int index = -1;

for (int i = 0; i size i contacts.length;

i++) {

if (contacts[i].cellPhone.equals(cellphone)) {

index = i;

break;

}

}

if (index == -1) {

System.out.println("该记录不存在!");

} else {

for (int i = index; i size; i++) {

contacts[index] = contacts[index + 1];

}

contacts[size - 1] = null;

size--;

System.out.println("删除成功!");

}

} else if (cmd.equals("4")) {

System.out.print("请输入要修改的手机号:");

String cellphone = scn.nextLine();

int index = -1;

for (int i = 0; i size i contacts.length;

i++) {

if (contacts[i].cellPhone.equals(cellphone)) {

index = i;

break;

}

}

if (index == -1) {

System.out.println("该记录不存在!");

} else {

System.out.print("请输入姓名:");

String name = scn.nextLine();

contacts[index].name = name;

}

}

} while (!cmd.equals("0"));

System.out.println("退出成功!");

scn.close();

System.exit(0);

}

}

学习JAVA开发上课录视频有用吗?

你好,肯定是有用的,古人云:温故而知新,说的就是这个道理。除非你是真·学霸,除非你勤学爱问,如果这些你都都不是,那录视频对你的帮助还是比加大。当然,你要是懒癌晚期,那谁都爱莫能助了。

java通讯录管理系统设计代码怎么编译

java编写这个通讯录管理系统

java编写这个通讯录管理系统_Java如何实现通讯录管理系统

咕噜噜在芬兰

原创

关注

3点赞·2305人阅读

Java如何实现通讯录管理系统

发布时间:2020-07-28 09:39:42

来源:亿速云

阅读:65

作者:Leah

这篇文章将为大家详细讲解有关Java如何实现通讯录管理系统,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

本文实例为大家分享了java实现通讯录管理系统的具体代码,供大家参考,具体内容如下

完成项目的流程:

1.根据需求,确定大体方向

2.功能模块分析

3.界面实现

4.功能模块设计

5.coding

6.代码测试

下面是源代码:import java.awt.Container;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.Scanner;

import java.util.concurrent.SynchronousQueue;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.WindowConstants;

import javax.swing.text.html.HTMLDocument.Iterator;

class Infro{

public String id;

public String name;

public String sex;

public String address;

public String e_mail;

public String phoneNumber;

static int index = 0;

static ArrayList list = new ArrayList();

static int len = list.size();

//构造函数

public Infro(String id,String name,String sex,String address,String e_mail,String phoneNumber){

this.id = id;

this.name = name;

this.sex = sex;

this.address = address;

this.e_mail = e_mail;

this.phoneNumber = phoneNumber;

}

public String toString(){

return "编号:"+id+" 姓名:"+name+" 性别:"+sex+" 通讯地址:"+address+" 邮箱地址:"+e_mail+" 电话:"+phoneNumber;

}

/**

* 添加功能

**/

public static void addFunction(){//添加功能

Infro infro = new Infro("","","","","","");

System.out.println("请输入添加的数据:");

Scanner in = new Scanner(System.in);

System.out.println("输入编号:");

infro.id = in.next();

System.out.println("输入姓名:");

infro.name = in.next();

System.out.println("输入性别:");

infro.sex = in.next();

System.out.println("输入通讯地址:");

infro.address = in.next();

System.

out.println("输入邮箱地址:");

infro.e_mail = in.next();

System.out.println("输入电话:");

infro.phoneNumber = in.next();

list.add(index,infro);

index++;

if(list.isEmpty()){

System.out.println("数据添加失败啦");

}else{

System.out.println("数据添加成功啦");

len++;//list集合长度加一

// System.out.println(list.get(0).toString());

}

}

// public static void deleteFunction(){//删除功能

// System.out.println("输入要删除的联系人的编号");

// Scanner in_2 = new Scanner(System.in);

// String d1 = in_2.nextLine();

// for(int a= 0; a

// if(d1.equals(list.get(a).id)){

// list.remove(list.get(a));

// len --;

// }

// }

// }

/**

* 删除功能

**/

public static void deleteFunction(){

System.out.println("输入要删除的联系人的编号");

Scanner in_2 = new Scanner(System.in);

String d1 = in_2.nextLine();

java.util.Iterator it = list.iterator();

while (it.hasNext()){

Infro infro = it.next();

if (infro.id.equals(d1)){

it.remove();

--index;//一定要加这个,否则当做了删除操作再做添加操作的时候会出现异常(类似于指针,栈)

System.out.println("删除完毕"+"此时通讯录记录条数为:" + --len);

}

}

}

/**

* 修改功能

**/

public static void reditFunction(){

System.out.println("输入要修改的通讯录的Id");

Scanner in_r = new Scanner(System.in);

String r1 = in_r.nextLine();

for(int a = 0; a len;a++){

if(r1.equals(list.get(a).id)){

System.out.println("输入修改后的姓名:");

String name_1 = in_r.next();

list.get(a).name = name_1;

System.out.println("输入修改后的性别:");

String sex_1 = in_r.next();

list.get(a).sex = sex_1;

System.out.println("输入修改后的通讯地址:");

String address_1 = in_r.next();

list.get(a).address = address_1;

System.out.println("输入修改后的邮箱地址:");

String e_mail_1 = in_r.next();

list.get(a).e_mail = e_mail_1;

System.out.println("输入修改后的电话:");

String phoneNumber_1 = in_r.next();

list.get(a).phoneNumber = phoneNumber_1;

System.out.println("数据修改完毕");

}

}

}

/**

* 查询功能

**/

public static void searchFunction() throws Exception{//查询功能

System.out.println("请输入要查询的姓名:");

Scanner in_1 = new Scanner(System.in);

String s1=in_1.nextLine();

for(int a= 0; a

if(s1.equals(list.get(a).name)){

System.out.println(list.get(a).toString());

}

}

}

/**

* 显示功能

**/

public static void showFunction(){

for(int i = 0 ;i

System.out.println(list.get(i).toString());

}

}

/**

* 保存功能

**/

public static void writeFunction() throws IOException{

FileWriter writer = new FileWriter("通讯录管理.txt");

for(int i = 0 ;i

String []strwriter = new String[len];

strwriter[i]=list.get(i).toString();

writer.write(strwriter[i]);

writer.write("\r\n");

System.out.println("成功写入一行数据到 通讯录管理.txt 中");

}

writer.close();//关闭写入流,释放资源

}

/**

* 读取功能

**/

public static void readFunction() throws IOException{

FileReader reader = new FileReader("通讯录管理.txt");

BufferedReader br = new BufferedReader(reader);

String str;

while((str = br.readLine()) != null){//每次读取一行文本,判断是否到达文件尾

System.out.println(str);

}

br.close();

}

}

public class Demo extends JFrame {

/**

* 界面设计

**/

public Demo(){

Container c = getContentPane(); //定义一个顶级容器c

JPanel jp = new JPanel(); //新建JPanel面板--jp

JButton button1 = new JButton("新建联系人");

JButton button2 = new JButton("删除联系人");

JButton button3 = new JButton("编辑联系人");

JButton button4 = new JButton("查找联系人");

JButton button5 = new JButton("显示所有联系人");

JButton button6 = new JButton("保存联系人到本地");

JButton button7 = new JButton("读取本地联系人");

jp.setLayout(new GridLayout(2,4,5,5));//新建网格布局管理器(行数,列数,组件间的水平垂直间距)

jp.add(button1);

jp.add(button2);

jp.add(button3);

jp.add(button4);

jp.add(button5);

jp.add(button6);

jp.add(button7);

c.add(jp);//将JPanel面板jp添加到顶级容器c中

setSize(600,500);

setTitle("*通 讯 录 管 理 系 统*");

setVisible(true);

setResizable(false);//窗体大小由程序员决定,用户不能自由改变大小

setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

/**

*按键响应

*

**/

button1.addActionListener(new ActionListener(){//添加功能实现

public void actionPerformed(ActionEvent arg0){

Infro.addFunction();

}

});

button2.addActionListener(new ActionListener(){//删除功能实现

public void actionPerformed(ActionEvent arg0){

Infro.deleteFunction();

}

});

button3.addActionListener(new ActionListener(){//修改功能实现

public void actionPerformed(ActionEvent arg0){

Infro.reditFunction();

}

});

button4.addActionListener(new ActionListener(){//查询功能实现

public void actionPerformed(ActionEvent arg0){

try {

Infro.searchFunction();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

button5.addActionListener(new ActionListener(){//显示功能实现

public void actionPerformed(ActionEvent arg0){

Infro.showFunction();

}

});

button6.addActionListener(new ActionListener(){//保存功能实现

public void actionPerformed(ActionEvent arg0){

try {

Infro.writeFunction();

} catch (IOException e) {

e.printStackTrace();

}

}

});

button7.addActionListener(new ActionListener(){//读取功能实现

public void actionPerformed(ActionEvent arg0){

try {

Infro.readFunction();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

}

public static void main(String[] args) {

// TODO Auto-generated method stub

new Demo();

Infro a = new Infro("", "", "", "", "", "");

}

}

关于Java如何实现通讯录管理系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

Java中的录入

importjava.util.*;classTest{publicstaticvoidmain(String[]args){Scannerx=newScanner(System.in);//构造一个Scanner对象,其传入参数为System.inSystem.out.print("请输入一个整数");inti=x.nextInt();//读取一个int数值System.out.println("你刚才输入的数为"+i);}}/*构造一个Scanner对象,其传入参数为System.in利用下列方法读取键盘数据:nextLine();//读取一行文本,可带空格next();//读取一个单词nextInt();//读取一个int数值nextDouble();//读取一个double数值用hasNextInt()和hasNextDouble()检测是否还有表示int或double数值的字符序列*/

关于录java和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。