
100分,100分,100分, 重要的事情说三遍~
我来1个参考案例
效果图
参考代码
import javaawtevent;import javaxswing;
import javaawt;
// 本来继承自JFrame 实现ActionListener接口
public class TextFrame extends JFrame implements ActionListener {
private final JTextArea jta;
boolean isBold, isItalic;
public TextFrame() {
jta = new JTextArea();
jtasetLineWrap(true); // 自动换行
Font font = new Font(FontDIALOG, FontPLAIN, 26);
jtasetFont(font);
JScrollPane jsp = new JScrollPane(jta);// 会自动生成滚动条的面板
add(jsp);
//菜单栏的创建和设置
JMenuBar menuBar = new JMenuBar();
JMenu menuFile = new JMenu("File");
JMenuItem jmia01 = new JMenuItem("About");
jmia01addActionListener(this);
JMenuItem jmia02 = new JMenuItem("Exit");
jmia02addActionListener(this);
menuFileadd(jmia01);
menuFileadd(jmia02);
JMenu menuFormat = new JMenu("Format");
JMenu menuColor = new JMenu("Color");
JMenuItem jmib01 = new JMenuItem("Blue");
jmib01addActionListener(this);
JMenuItem jmib02 = new JMenuItem("Red");
jmib02addActionListener(this);
JMenuItem jmib03 = new JMenuItem("Yellow");
jmib03addActionListener(this);
menuColoradd(jmib01);
menuColoradd(jmib02);
menuColoradd(jmib03);
JMenu menuFont = new JMenu("Font");
JMenuItem jmic01 = new JMenuItem("Bold");
jmic01addActionListener(this);
JMenuItem jmic02 = new JMenuItem("Italic");
jmic02addActionListener(this);
menuFontadd(jmic01);
menuFontadd(jmic02);
menuFormatadd(menuColor);
menuFormatadd(menuFont);
menuBaradd(menuFile);
menuBaradd(menuFormat);
setJMenuBar(menuBar);//设置菜单栏
setTitle("文本编辑窗口"); // 设置标题
setSize(520, 350);//设置窗口大小
setLocationRelativeTo(null);//设置窗口居中
setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口点击关闭按钮时,退出
}
@Override
public void actionPerformed(ActionEvent e) {
String cmd = egetActionCommand();// 获取ActionCommand ,用于判断是哪一个按钮被点击了
if (cmdequals("Exit")) {
Systemexit(0);
} else if (cmdequals("About")) {
JOptionPaneshowMessageDialog(this, "程序版本Ver10", "About", JOptionPaneINFORMATION_MESSAGE);
} else if (cmdequals("Blue")) {
jtasetForeground(ColorBLUE);
} else if (cmdequals("Red")) {
jtasetForeground(ColorRED);
} else if (cmdequals("Yellow")) {
jtasetForeground(ColorYELLOW);
} else if (cmdequals("Bold")) { // 第一次选择Bold 会加粗,第二次选择Bold会取消加粗
isBold = !isBold;
if (isBold) {
jtasetFont(new Font(FontDIALOG, FontBOLD, 26));
} else {
jtasetFont(new Font(FontDIALOG, FontPLAIN, 26));
}
} else if (cmdequals("Italic")) {
isItalic = !isItalic;
if (isItalic) {
jtasetFont(new Font(FontDIALOG, FontITALIC, 26));
} else {
jtasetFont(new Font(FontDIALOG, FontPLAIN, 26));
}
}
}
public static void main(String[] args) {
new TextFrame()setVisible(true);// 创建窗口设置可见
}
}
给你例子吧,自己研究
int Menu_popu(int x1,int y1,int x2,int y2,P_U8 MainMenu,int count,int Menucount,int linex1,int liney1,int linex2,int liney2)//被调函数
{
int i,j,choice,displayfir,Maxkey;
uchar k;
screen(1);
choice=0;displayfir=0;Maxkey=Menucount+48;
do
{
clsn(x1,x2-x1+1);
drawrect(linex1,liney1,linex2,liney2);
j=0;
for(i=displayfir;i<displayfir+count && i<Menucount;i++,j++)
{
moveto(x1+2j,y1);
if(i==choice){putstr_x(MainMenu[i],1);}
else{putstr(MainMenu[i]);}
}//for
k=key(0);
if(k==KEY_ENTER){if(choice==Menucount-1)return MSG_ESC;else return choice;}
else if(k==KEY_F2){return MSG_ESC;}
else if(k==KEY_DOWN){choice++; if(choice==Menucount) {choice--;}
if((choice%count)==0) {displayfir=choice;}
}
else if(k==KEY_UP){choice--; if(choice<0) {choice=0;}
if(((choice+1)%count)==0) {displayfir=choice+1-count;}
}
else if(0x30<k&&k<=(Maxkey-displayfir-1)){return (k-0x31);}
}while(1);
}
void MainMenu(void)//主调函数
{
uchar s[12];
int i;
while (1)
{ //进入功能菜单选择
cls();moveto(19,18);putstr(" ");
memset(s,0,sizeof(s));
getdate(s);moveto(19,2); putstr("日期: "); putn_h(10,s);
i=Menu_popu(1,3,18,20,Menu,8,8,10,10,135,135);
if(i==0)SUB_ADD();//补抄
else if(i==1)SUB_APPEND();//续抄
else if(i==2)SUB_CB();//抄表
else if(i==3)SUB_ABNORMAL();//异常
else if(i==4)SUB_CHECK();//查询
else if(i==5)SUB_SUM();//统计
else if(i==MSG_ESC){libclose(0);return;}//退出
}
}
int createmenu(char filename[])
{
SMenuinfo menu;
//将file1指针与文件filename关联,filename由主函数提供
ofstream file1(filename,ios::out|ios::binary);
if (!file1)
{
cout<<"cannot open output file\n";
return 0;
}
printf("请输入餐馆所有的菜式的编号,名称,单价(用空格分隔)\n");
for (int i=0;i<3;i++)
{
scanf("%s%s%s",&menunum,&menuname,&menuprice);
//将结构体menu的数据写入文件
file1write((char )&menu,sizeof(SMenuinfo));
}
file1close();
return 1;
}
//请修改checkbill函数结账功能
int printmenu(char filename[100],SMenuinfo menu[],int count)
{
// filename是文件名,menu是存储文件读出信息的结构体数组,count表示数组的大小
//将file1指针与文件filename关联,filename由主函数提供
ifstream file1(filename,ios::in|ios::binary);
if (!file1)
{
cout<<"cannot open output file\n";
return 0;
}
for (int i=0;i<count;i++)
{
//将文件内容读取出来存放在结构体menu[i]中
file1read((char )&menu[i],sizeof(SMenuinfo));
}
file1close();
return 1;
}
5个函数的实现么
#include <stdioh>#include <stdlibh>
#include <stringh>
int createArray( int n )
{
int i, a;
a = (int)malloc( nsizeof(int) );
memset( a, 0, nsizeof(int) );
printf( "输入 %d 个整数:\n", n );
for( i=0; i<n; i++ )
scanf( "%d", &a[i] );
fflush( stdin );
return a;
}
void printArray( int a, int n )
{
int i;
if ( a == NULL ) return;
for( i=0; i<n; i++ )
{
printf( "%5d ", a[i] );
if ( i%5 == 0 && i!=0 )
printf( "\n" );
}
printf( "\n" );
}
void bubbleSort( int a, int n )
{
int i,j;
if ( a == NULL ) return;
for( i=0; i<n; i++ )
for( j=i; j<n; j++ )
if( a[i] > a[j] )
{
int t = 0;
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
int binarySearch( int a, int n, int tofind )
{
int i,high, low, mid ;
high = n-1;
low = 0;
mid = (low+high) / 2;
if ( a == NULL ) return -1;
while( high > low )
{
mid = (low+high)/2;
if ( a[mid] > tofind )
high = mid;
else if ( a[mid] < tofind )
low = mid;
else
return mid;
}
return -1;
}
void reverseArray( int a, int n )
{
int i;
if ( a == NULL ) return;
for( i=0; i<n/2; i++ )
{
int t;
t = a[i];
a[i] = a[n-i-1];
a[n-i-1] = t;
}
}
int main()
{
int a=NULL,c=0, n;
printf( "menu\n" );
printf( "input your choice[0-5]:" );
scanf( "%d", &c );
fflush( stdin );
while( c!=0 )
{
switch( c )
{
case 1:
printf( "input array length:" );
scanf( "%d", &n );
fflush( stdin );
if ( n<=0 )
printf( "input invalid,%d\n", n );
else
{
if ( a!= NULL ) free( a );
a = createArray( n );
}
break;
case 2:
printArray( a, n );
break;
case 3:
bubbleSort( a, n );
break;
case 4:
{
int tofind = 0, idx=-1;
printf( "which number you want to search:" );
scanf( "%d", &tofind );
fflush( stdin );
idx = binarySearch( a, n, tofind );
if ( idx < 0 )
printf( "%d not find\n", tofind );
else
printf( "%d found at index %d\n", tofind, idx );
break;
}
case 5:
reverseArray( a, n );
printArray( a, n );
break;
}
printf( "input your choice[0-5]:" );
scanf( "%d", &c );
fflush(stdin);
}
}
给你一个简单的菜单程序吧。其中的子函数,填充成楼主所需即可。
#include <stdioh>/子函数1/
fun1() {
printf ("子函数1\n");
}
/子函数2/
fun2() {
printf ("子函数2\n");
}
/子函数3/
fun3() {
printf ("子函数3\n");
}
/子函数4/
fun4() {
printf ("子函数4\n");
}
int main(void) {
int key; /命令编号/
do {
system("cls"); /清屏/
/打印菜单/
printf ("======================================================\n");
printf (" #\t功能详情\n");
printf ("------------------------------------------------------\n");
printf (" 1\t功能1\n");
printf (" 2\t功能2\n");
printf (" 3\t功能3\n");
printf (" 4\t功能4\n");
printf (" 5\t退出\n");
printf ("======================================================\n");
printf ("\n");
printf("请输入命令编号以开启 *** 作:");
/输入命令编号/
scanf("%d",&key);
printf ("\n");
/switch函数实现输入功能序号执行相应函数/
switch (key) {
case 1: fun1(); break; /子函数1/
case 2: fun2(); break; /子函数2/
case 3: fun3(); break; /子函数3/
case 4: fun4(); break; /子函数4/
case 5: printf("程序结束!按任意键退出\n\n"); break;
default:printf("输入错误,请重新输入!\n\n"); break;
}
/屏幕暂留/
if (key!=5) {
printf ("\n");
printf("按Enter键继续\n");
printf ("\n");
fflush(stdin);
getch ();
}
} while (key!=5);
/屏幕暂留/
fflush(stdin);
getch ();
return 0;
}
运行结果
以上就是关于java设计一个创建二级菜单的程序。全部的内容,包括:java设计一个创建二级菜单的程序。、求!设计一个菜单程序,列出所作设计的全部功能,运行时可以通过选择菜单,调用相应函数实现功能,输出结果、c++设计一个餐厅当日菜单生成程序,实现的功能为:能够产生菜单并浏览内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)