首页 > 编程知识 正文

java语言实现光标式的菜单的简单介绍

时间:2023-12-24 12:05:40 阅读:320737 作者:ZZVW

本文目录一览:

JAVA可不可以自定义光标?

可以,在Frame 或者 Applet中用setCursor(Cursor cursor)设置鼠标样式

至于Cursor的建立需要用java.awt.Toolkit类的

createCustomCursor(Image cursor, Point hotSpot, String name)方法,

建立,你自己查看API吧

用Java语言编程实现一个图书管理系统的主菜单。

#include iostream

#include string //C++磁盘操作头文件

#include istream

#include fstream

#include iomanip//自定义输出宽度

using namespace std;

struct Book //结构类型

{

string bookname;//书名

string author;//作者名

Book *next;

};

class BookList

{

public:

BookList(){first=new Book;first-next=NULL;}

int NewBook();

void SOldBook();

void testread();

void testwrite();

void DisplayBook();

~BookList();

private:

Book *first;

int j;

};

int BookList::NewBook()

{

Book *s;s=new Book; //为插入的新书申请结点

Book *q;q=new Book;

Book *p;p=new Book;

cout"输入新书书名:";

cins-bookname;

cout"输入作者:";

cins-author;

p=first;q=first; //建立链表

if(first-next==NULL)//如果原链表为空,把新书的结点插入到链表中

{

first-next=s; //头插法

s-next=NULL;

}

else{

while(p-next-booknames-bookname)//按书名排序插入

{

p=p-next;

if(p-next==NULL)break;

}

s-next=p-next;

p-next=s;

}

return 1;

}

void BookList::SOldBook() //查询

{

Book *s;s=new Book;

Book *p;p=new Book;

cout"输入你要查询的书名:";

cins-bookname;

p=first-next;

while(p-bookname!=s-bookname)

{

p=p-next;//接着查找下一个结点

if(p==NULL)break;

}

if(p==NULL)

cout"你所查询的书没找到!"endl;

else

cout"找到:《"p-bookname"》 "p-authorendl;

}

void BookList::testread()

{

ifstream in;j=0;//读出文件流

in.open("BookList.txt",ios::in);//以读的形式打开原文件

if(!in)

{

cerr"错误!不能打开文件!";

exit(1);

}

Book *q;q=new Book;

Book *p;p=new Book;

p=first;

cout"从BookList.txt中读出已有图书如下:"endl;

while(!in.eof())//判断文件是否为空

{

inq-booknameq-author;//从文件里面读到链表

coutq-bookname" "q-authorendl;

j++;

p-next=q;

p=q;

q-next=new Book;

q=q-next;

}

p-next=NULL;

cout"共有图书"j"本"endlendl;

in.close();

}

void BookList::DisplayBook()

{

j=0;

cout"本馆现有书籍有:"endl;

Book *p;p=new Book;

p=first-next;

while(p!=NULL) //输出链表中的元素

{

coutp-bookname" "p-authorendl;

p=p-next;

j++;

}

cout"共有图书"j"本"endl;

}

void BookList::testwrite()

{

ofstream out; //写入文件流

out.open("BookList.txt",ios::out);

if(!out)

{

cerr"错误!不能打开文件!";

exit(1);

}

Book *p;p=new Book;

for(p=first-next;p!=NULL;p=p-next)

{

outp-bookname't'p-authorendl; //把链表中的元素写到文件中

}

out.close();

}

BookList::~BookList() //析构函数

{

Book *p;p=new Book;

Book *q;q=new Book;

p=first-next;

while(p)

{

q=p;

p=p-next;

delete q;

}

}

void main()

{

char s;

int i,k,count=0;

BookList L; //定义对象

L.testread(); //把文件中的内容读到链表中

while(1)

{

char *menu[]={"输入新书","查询旧书","显示所有图书","退出",""}; //字符串指针数组

for(i=0;menu[i][0]!='';i++)

couti+1"、 "menu[i]endl;

cink;

switch(k)

{

case 1:count=L.NewBook();break;

case 2:L.SOldBook();break;

case 3:L.DisplayBook();break;

default:if(k!=4)cout"输入错误!"endl;break;

}

if(k==4)

{ if(count)

{ cout"修改后的BookList.txt未保存,是否保存?(y/n):";

cins;

if(s=='y')

L.testwrite();

}

break;

}

}

}

java 写了一个记事本的界面,怎样才能把光标移到菜单条下面?

import javax.swing.JFrame;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JTextArea;

public class TestNotebook extends JFrame{

public TestNotebook() {

this.setTitle("记事本");

JMenuBar menu_bar = new JMenuBar();

menu_bar.setSize(10000,20);

//这里加入JMenuBar有专门的函数

this.setJMenuBar(menu_bar);

JTextArea txt=new JTextArea();

//还有这里 添加控件是这样 这里不是AWT

this.getContentPane().add(txt);

this.setBounds(300, 100, 800, 600);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

JMenu F=new JMenu("文件(F)");

JMenu E=new JMenu("编辑(E)");

JMenu O=new JMenu("格式(O)");

JMenu V=new JMenu("查看(V)");

JMenu H=new JMenu("帮助(H)");

menu_bar.add(F);

menu_bar.add(E);

menu_bar.add(O);

menu_bar.add(V);

menu_bar.add(H);

}

public static void main(String[] args) {

TestNotebook Notebook=new TestNotebook();

Notebook.setVisible(true);

}

}

java中的光标的用法?????

可以新建一个robert类

然后mousemove(x,y)鼠标移动

mouseprise(button1 or 2 or 3)鼠标左键中间右键操作

这样就可以用java控制鼠标光标了

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。