「窗口程序java」窗口程序Java
本篇文章给大家谈谈窗口程序java,以及窗口程序Java对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、JAVA如何给程序设置一个窗口
- 2、java如何操作窗口化程序
- 3、java窗口程序开发
- 4、如何用JAVA设计程序窗口
- 5、如何在windows命令行窗口运行Java程序
- 6、java窗口程序制作
JAVA如何给程序设置一个窗口
首先,绘制一个默认的窗体,创建好工程,包,类,命名类为Window.很简单,在类中添加一个私有属性JFrame,这么写:private JFrame f = new JFrame("欢迎来到本自助银行");Window的构造方法中,只写 f.setVisible(true);以及窗体的初始位置和初始大小:f.setLocation(300, 200);f.setSize(800, 500);
然后在同一个构造函数中跟进一行f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);此为设置关闭图标即退出程序紧接着,写f.setResizable(false);此为设置不可更改窗体大小。如图,的确没办法更改了。
最后,便是画龙点睛的一笔,给窗体添加一个图标,显得更专业了一些:f.setIconImage(Toolkit.getDefaultToolkit().createImage("E:\\a.jpg"));
这里有一点比较重要,重申一句。构造器中的设置比静态属性初始化设置更有直接影响力。而且,程序是执行向上覆盖的。也就是说,如果之后有过更改,那么更改之后就显示更改后的结果,比如,在这个构造函数中再写f.setTitle("好好活着");那么,请注意窗体的文字。如图:
java如何操作窗口化程序
给一个登录的,不错,我用的
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/*
APPLET
CODE=dialoginput.class
WIDTH=300
HEIGHT=200
/APPLET
*/
public class dialoginput extends JApplet implements ActionListener
{
JLabel top=new JLabel("Welcome to cn-java net !");
JButton display=new JButton("会员登录");
JLabel welcomeword=new JLabel(" 您还没有登录 ");
JLabel title=new JLabel(" 登 录 窗 口 "),
name=new JLabel("会员名:"),
password=new JLabel("密码:");
JTextField inputname=new JTextField(12);
JPasswordField inputpassword=new JPasswordField(12);//与AWT不同的是,Swing有一个用于口令的特殊控件,就是JPasswordField
JButton ok=new JButton("确定"),
cancel=new JButton("放弃");
private JDialog dialog=new JDialog((Frame)null,"登录",true);
public void init()
{
Container contentPane=getContentPane();
Container dialogContentPane=dialog.getContentPane();
JPanel p=new JPanel();
contentPane.setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridy=0;
contentPane.add(top,gbc);
gbc.gridx=GridBagConstraints.RELATIVE;
gbc.gridy=1;
contentPane.add(display,gbc);
gbc.gridx=GridBagConstraints.RELATIVE;
gbc.gridy=2;
contentPane.add(welcomeword,gbc);
dialogContentPane.setLayout(new GridBagLayout());
GridBagConstraints gbb=new GridBagConstraints();
gbb.gridx=1;
gbb.gridy=0;
dialogContentPane.add(title,gbb);
gbb.gridx=GridBagConstraints.RELATIVE;
gbb.gridy=1;
dialogContentPane.add(name,gbb);
dialogContentPane.add(inputname,gbb);
gbb.gridx=GridBagConstraints.RELATIVE;
gbb.gridy=2;
dialogContentPane.add(password,gbb);
dialogContentPane.add(inputpassword,gbb);
inputpassword.setEchoChar('*');
gbb.gridx=GridBagConstraints.RELATIVE;
gbb.gridy=3;
p.setLayout(new FlowLayout());
p.add(ok);
p.add(cancel);
gbb.gridx=1;
gbb.gridy=4;
dialogContentPane.add(p,gbb);
display.addActionListener(this);
ok.addActionListener(this);
cancel.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==display){
dialog.setBounds(200,200,300,200);
dialog.show();
}else if(e.getSource()==ok){
welcomeword.setText("您好,"+inputname.getText()+",欢迎光临中文Java技术网!");
}else if(e.getSource()==cancel){
welcomeword.setText("你没有输入!");
}
dialog.setVisible(false);
}
}
java窗口程序开发
/*
*
*题目:记事本程序
*Author: Jeason
*
* 2004-12-20
*
**/
package jeason;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class Jsb{
///
boolean dirty=true;
String filename=;
String strtext=;
///////////////////////////////////
////////// Menu ////////////////
///////////////////////
JFrame frame=new JFrame(我的记事本);
JPopupMenu pop=new JPopupMenu(弹出);
JTextArea text=new JTextArea();
JLabel statubar=new JLabel(状态栏);
JMenuBar Mbar=new JMenuBar();
JFileChooser jFileChooser1=new JFileChooser();
JColorChooser jColor=new JColorChooser();
JMenu jFile=new JMenu(文件);
JMenu jEdit=new JMenu(编辑);
JMenu jFormat=new JMenu(格式);
JMenu jHelp=new JMenu(帮助);
JMenuItem jnew=new JMenuItem(新建(N));
public Jsb(){ ///无参数的构造函数
///
this.dirty=false;
/////
final BorderLayout borderLayout1=new BorderLayout();
frame.setSize(600,500);//
frame.addWindowListener(new Jsb_frame_closingAdapter(this));
JPanel panel=new JPanel();
panel.setLayout(borderLayout1);//布局
panel.add(new JScrollPane(text));//滚动条
panel.add(statubar,borderLayout1.SOUTH);
frame.getContentPane().add(panel);
//
frame.setJMenuBar(Mbar); //将主菜单添加到窗体中
/*
* jnew
**/
//jnew
jnew.addActionListener(new File_new_actionAdapter(this));
jnew.setMnemonic(´N´);//N上下划线
jnew.setAccelerator(KeyStroke.getKeyStroke(´N´,java.awt.Event.CTRL_MASK,true));
//快捷方式
/*
* jopen
**/
JMenuItem jopen=new JMenuItem(打开(O));//jopen
jopen.addActionListener(new File_open_actionAdapter(this));
jopen.setMnemonic(´O´);
jopen.setAccelerator(KeyStroke.getKeyStroke(´O´,java.awt.Event.CTRL_MASK,true));
/*
* jsave
**/
JMenuItem jsave=new JMenuItem(保存(S));
jsave.addActionListener(new File_save_actionAdapter(this));
jsave.setMnemonic(´S´);
jsave.setAccelerator(KeyStroke.getKeyStroke(´S´,java.awt.Event.CTRL_MASK,true));
/*
* jsave as
**/
JMenuItem jsaveas=new JMenuItem(另存为...);
jsaveas.addActionListener(new File_saveas_actionAdapter(this));
/*
* jquite
**/
JMenuItem jquite=new JMenuItem(关闭(Q));
jquite.addActionListener(new File_quite_actionAdapter(this));
jquite.setMnemonic(´Q´);
jquite.setAccelerator(KeyStroke.getKeyStroke(´Q´,java.awt.Event.CTRL_MASK,true));
//------------------------------------
// jFile code of end
//--------------------------------------
/**
* jEdit code
*/
//jundo
JMenuItem jundo=new JMenuItem(撤销(U));
jundo.addActionListener(new Edit_undo_actionAdapter(this));
jundo.setMnemonic(´U´);
jundo.setAccelerator(KeyStroke.getKeyStroke(´U´,java.awt.Event.CTRL_MASK,true));
/*
* jcut
**/
JMenuItem jcut=new JMenuItem(剪切(X));
jcut.addActionListener(new Edit_cut_actionAdapter(this));
jcut.setMnemonic(´X´);
jcut.setAccelerator(KeyStroke.getKeyStroke(´X´,java.awt.Event.CTRL_MASK,true));
/*
* jcopy
**/
JMenuItem jcopy=new JMenuItem(复制(C));
jcopy.addActionListener(new Edit_copy_actionAdapter(this));
jcopy.setMnemonic(´C´);
jcopy.setAccelerator(KeyStroke.getKeyStroke(´C´,java.awt.Event.CTRL_MASK,true));
/*
* jpaste
**/
JMenuItem jpaste=new JMenuItem(粘贴(V));
jpaste.addActionListener(new Edit_paste_actionAdapter(this));
jpaste.setMnemonic(´V´);
jpaste.setAccelerator(KeyStroke.getKeyStroke(´V´,java.awt.Event.CTRL_MASK,true));
/*
* jdelete
**/
JMenuItem jdelete=new JMenuItem(删除(D));
jdelete.addActionListener(new Edit_delete_actionAdapter(this));
jdelete.setMnemonic(´D´);
jdelete.setAccelerator(KeyStroke.getKeyStroke(´D´,java.awt.Event.CTRL_MASK,true));
/*
* jfind
**/
JMenuItem jfind=new JMenuItem(查找(F));
jfind.addActionListener(new Edit_find_actionAdapter(this));
jfind.setMnemonic(´F´);
jfind.setAccelerator(KeyStroke.getKeyStroke(´F´,java.awt.Event.CTRL_MASK,true));
/*
* jreplace
**/
JMenuItem jreplace=new JMenuItem(替换(R));
jreplace.addActionListener(new Edit_replace_actionAdapter(this));
jreplace.setMnemonic(´R´);
jreplace.setAccelerator(KeyStroke.getKeyStroke(´R´,java.awt.Event.CTRL_MASK,true));
/*
*jselectall
**/
JMenuItem jselectall=new JMenuItem(全选(A));
jselectall.addActionListener(new Edit_selectall_actionAdapter(this));
jselectall.setMnemonic(´A´);
jselectall.setAccelerator(KeyStroke.getKeyStroke(´A´,java.awt.Event.CTRL_MASK,true));
/*
* jdate
**/
JMenuItem jdate=new JMenuItem(日期/时间(T));
jdate.addActionListener(new Edit_timedate_actionAdapter(this));
jdate.setMnemonic(´T´);
jdate.setAccelerator(KeyStroke.getKeyStroke(´T´,java.awt.Event.CTRL_MASK,true));
//------------------------------
// jEdit code of end
//
//-----------------------------
/*
* jword
**/
JMenuItem jword=new JMenuItem(自动换行);
jword.addActionListener(new Format_word_actionAdapter(this));
/*
* jfont
**/
JMenuItem jfont=new JMenuItem(字体..);
jfont.addActionListener(new Format_font_actionAdapter(this));
/*
* jcolor
**/
JMenuItem jcolor=new JMenuItem(颜色...);
jcolor.addActionListener(new Format_color_actionAdapter(this));
//--------------------------------------------------
// jFormat code of end
//--------------------------------------------------
/*
* jabout
**/
JMenuItem jabout=new JMenuItem(关于作者(A));
jabout.addActionListener(new Help_about_actionAdapter(this));
jabout.setMnemonic(´A´);
jabout.setAccelerator(KeyStroke.getKeyStroke(´A´,java.awt.Event.CTRL_MASK,true));
//-------------------------------------------------
// jHelp code of end
//------------------------------------------------------
/*************************************************
*------------------------------------------------
* PopupMenuItem
*------------------------------------------------
*************************************************/
/*
* pundo
**/
JMenuItem pundo=new JMenuItem(撤销(U));
pundo.addActionListener(new Pop_undo_actionAdapter(this));
pundo.setMnemonic(´U´);
pundo.setAccelerator(KeyStroke.getKeyStroke(´U´,java.awt.Event.CTRL_MASK,true));
/*
* pcut
**/
JMenuItem pcut=new JMenuItem(剪切(X));
pcut.addActionListener(new Pop_cut_actionAdapter(this));
pcut.setMnemonic(´X´);
pcut.setAccelerator(KeyStroke.getKeyStroke(´X´,java.awt.Event.CTRL_MASK,true));
/*
* pcopy
**/
JMenuItem pcopy=new JMenuItem(复制(C));
pcopy.addActionListener(new Pop_copy_actionAdapter(this));
pcopy.setMnemonic(´C´);
pcopy.setAccelerator(KeyStroke.getKeyStroke(´C´,java.awt.Event.CTRL_MASK,true));
/*
* ppaste
**/
JMenuItem ppaste=new JMenuItem(粘贴(V));
ppaste.addActionListener(new Pop_paste_actionAdapter(this));
ppaste.setMnemonic(´V´);
ppaste.setAccelerator(KeyStroke.getKeyStroke(´V´,java.awt.Event.CTRL_MASK,true));
/*
*pdelete
**/
JMenuItem pdelete=new JMenuItem(删除(D));
pdelete.addActionListener(new Pop_delete_actionAdapter(this));
pdelete.setMnemonic(´D´);
pdelete.setAccelerator(KeyStroke.getKeyStroke(´D´,java.awt.Event.CTRL_MASK,true));
////////
///////////// text////////////////////////////////////////
text.setDoubleBuffered(false);
text.setToolTipText(杨勇的记事本);
text.setVerifyInputWhenFocusTarget(true);
text.setText();
text.addCaretListener(new Jsb_text_caretAdapter(this));
text.addMouseListener(new Jsb_text_mouseAdapter(this));
text.addAncestorListener(new Jsb_text_ancestorAdapter(this));
//////////////////////////////////////////////////////////
Mbar.add(jFile);
Mbar.add(jEdit);
Mbar.add(jFormat);
Mbar.add(jHelp);
jFile.add(jnew);
jFile.add(jopen);
jFile.addSeparator();
jFile.add(jsave);
jFile.add(jsaveas);
jFile.addSeparator();
jFile.add(jquite);
jEdit.add(jundo);
jEdit.addSeparator();
jEdit.add(jcut);
jEdit.add(jcopy);
jEdit.add(jpaste);
jEdit.add(jdelete);
jEdit.addSeparator();
jEdit.add(jfind);
jEdit.add(jreplace);
jEdit.addSeparator();
jEdit.add(jselectall);
jEdit.add(jdate);
jFormat.add(jword);
jFormat.addSeparator();
jFormat.add(jfont);
jFormat.addSeparator();
jFormat.add(jcolor);
jHelp.add(jabout);
pop.add(pundo);
pop.addSeparator();
pop.add(pcut);
pop.add(pcopy);
pop.add(ppaste);
pop.add(pdelete);
frame.setVisible(true);
}
/************************************************************
//////////////////////Event/////////////////////////////////
**************************************************************/
public void frame_windowclose_windowClosing(WindowListener e){
this.close();
}
/////////////////////////////////////////////////////////
public void text_mouseClicked(MouseEvent e){
if(e.getModifiers()==InputEvent.BUTTON3_MASK){
pop.show((Component)e.getSource(),e.getX(),e.getY());
}
}
public void text_ancestorAdded(AncestorEvent e){
this.dirty=false;
this.newtext();
}
public void text_caretUpdate(CaretEvent e)
{
this.dirty=true;
//this.statubar.setText(this.text.getText());
}
///////////// File /////////////////////////////////////
public void File_open_actionPerformed(ActionEvent e){
//打开的事件
this.opentext();
}
public void File_new_actionPerformed(ActionEvent e){
///新建的事件
this.newtext();
}
public void File_save_actionPerformed(ActionEvent e){
//保存的事件
this.save();
}
public void File_saveas_actionPerformed(ActionEvent e){
//另存为
this.saveas();
}
public void File_quite_actionPerformed(ActionEvent e){
this.close();
}
////////////////// Edit /////////////////////////////////////
public void Edit_undo_actionPerformed(ActionEvent e){
//撤销
this.undo();
}
public void Edit_cut_actionPerformed(ActionEvent e){
//剪切
this.cut();
}
public void Edit_copy_actionPerformed(ActionEvent e){
//复制
this.copy();
}
public void Edit_paste_actionPerformed(ActionEvent e){
//粘贴
this.paste();
}
public void Edit_delete_actionPerformed(ActionEvent e){
//删除
this.delete();
}
public void Edit_find_actionPerformed(ActionEvent e){
//查找
int cu=this.text.getCaretPosition();
int end=this.text.getText().length();
FindDlg fd=new FindDlg(frame,查找,true);
fd.show();
String str=fd.getFindStr().trim();
if(fd.getFlag()){
this.nextFindStr(str,cu,end);
}else{
this.upFindStr(str,cu);
}
}
public void Edit_replace_actionPerformed(ActionEvent e){
//替换
int cu=this.text.getCaretPosition();
int end=this.text.getText().length();
ReplaceDlg rd=new ReplaceDlg(frame,替换,true);
rd.show();
this.replaceStr(rd.findStr().trim(),rd.replaceStr().trim(),cu,end);
}
public void Edit_selectall_actionPerformed(ActionEvent e){
//全选
this.text.setSelectionStart(0);
this.text.setSelectionEnd(this.text.getText().length());
}
public void Edit_timedate_actionPerformed(ActionEvent e){
//时间日期
SimpleDateFormat sdf = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);
this.text.append( 当前时间:+sdf.format(new Date()));
}
///////////// Format//////////////////////////////////////
public void Format_word_actionPerformed(ActionEvent e){
//自动换行
if(!this.text.getLineWrap()){
this.text.setLineWrap(true);
}
else{
this.text.setLineWrap(false);
}
}
public void Format_font_actionPerformed(ActionEvent e){
//字体常规,斜体,粗体,粗斜体
Font cur=this.text.getFont();
int type=Font.BOLD;
FontSet fs=new FontSet(frame,字体设置,true);
fs.show();
if(fs.flag){
switch(fs.font2()){
case 0:type=Font.PLAIN;break;
case 1:type=Font.ITALIC;break;
case 2:type=Font.BOLD; break;
case 3:type=Font.ROMAN_BASELINE;break;
default:type=Font.PLAIN;break;
}
Font f=new Font(fs.font1(),type,16);
this.text.setFont(f);
}else{
this.text.setFont(cur);
}
}
public void Format_color_actionPerformed(ActionEvent e){
// 颜色
Color current=this.text.getForeground();
this.jColor.setColor(current);
this.text.setForeground(
this.jColor.showDialog(text,选择颜色,current));
}
//////////////////// Help /////////////////////////////////////
public void Help_about_actionPerformed(ActionEvent e){
//关于作者
new AboutDlg();
}
////////////////////////////////////////////////////////
public void pop_undo_actionPerformed(ActionEvent e){
//Pop undo
this.undo();
}
public void pop_cut_actionPerformed(ActionEvent e){
//pop cut
this.cut();
}
public void pop_copy_acionPerformed(ActionEvent e){
//pop copy
this.copy();
}
public void pop_paste_actionPerformed(ActionEvent e){
//pop paste
this.paste();
}
public void pop_delete_actionPerformed(ActionEvent e){
//pop delete
this.delete();
}
/************************************************************
/////////////////////////////////////////////////////////////
////////////// coustm function ///////////////////////////////
/////////////////////////////////////////////////////////////
************************************************************/
void close(){
if(this.dirty){
Dlgtext Dt=new Dlgtext(frame,提示,true);
Dt.show();
if(Dt.getCheck()){
this.save();
}
else {
frame.dispose();
System.exit(0);
}
}else{
frame.dispose();
System.exit(0);
}
}
void newtext(){//新建
if((!this.dirty)||(!this.saveas())){
this.text.setText();
this.text.setFocusable(true);
this.frame.setTitle(未命名-----Author:Jeason);
this.statubar.setText(新建文本);
}
else this.saveas();
}
void opentext(){//打开
//
String strFileOpen=;
if(!this.dirty){
try{
if(this.jFileChooser1.APPROVE_OPTION==
this.jFileChooser1.showOpenDialog(frame)){
strFileOpen=this.jFileChooser1.getSelectedFile().getPath();
File file=new File(strFileOpen);
int flength=(int)file.length();
int num=0;
FileReader fReader=new FileReader(file);
char[] data=new char[flength];
while(fReader.ready()){
num+=fReader.read(data,num,flength-num);
}
fReader.close();
this.text.setText(new String(data,0,num));
this.filename=strFileOpen;
this.frame.setTitle(this.filename);
this.statubar.setText(Open File:+this.filename);
this.dirty=false;
}else
{
return ;
}
}catch(Exception e){
this.statubar.setText(Error Open:+e.getMessage());
}
}else{
this.save();
}
}
boolean save(){//保存
if(this.dirty){
if(this.filename.length()!=0){
try{
File saveFile=new File(this.filename);
FileWriter fw=new FileWriter(saveFile);
fw.write(this.text.getText());
fw.close();
this.dirty=false;
this.statubar.setText(保存文件:+this.filename);
return true;
}catch(Exception e)
{
this.statubar.setText(保存出错: +e.getMessage());
return false;
}
}else{
return this.saveas();
}
}else{
return true;
}
}
boolean saveas(){//另存为
if(this.jFileChooser1.APPROVE_OPTION==this.jFileChooser1.showSaveDialog(frame)){
this.filename=this.jFileChooser1.getSelectedFile().getPath();
return this.save();
}else{
return false;
}
}
void undo(){
//undo
}
void cut(){
//cut
try{
String str=this.text.getSelectedText();
if(str.length()!=0){
this.strtext=str;
this.text.replaceRange(,this.text.getSelectionStart(),this.text.getSelectionEnd());
this.dirty=true;
}
}catch(Exception ex){
this.statubar.setText(剪切出错:+ex.getMessage());
}
}
void copy(){
//copy
try{
String str=this.text.getSelectedText();
if(str.length()!=0){
this.strtext=str;
}
}catch(Exception ex)
{
this.statubar.setText(复制出错!+ex.getMessage());
}
}
void paste(){
//paste
if(this.strtext.length()0){
this.text.insert(this.strtext,this.text.getCaretPosition());
this.dirty=true;
}
}
void delete(){
//delete
this.text.replaceRange(,this.text.getSelectionStart(),this.text.getSelectionEnd());
this.dirty=true;
}
void nextFindStr(String str,int cur,int end){
if(curend){
this.statubar.setText(没有找到!);
}
else{
int i=this.text.getText().indexOf(str);
if(i=0){
this.text.setSelectionStart(i);
this.text.setSelectionEnd(i+str.length());
this.statubar.setText(已经在:+i+ 位置找到!);
}
else{
nextFindStr(str,++cur,end);
}
}
}
void upFindStr(String str,int cur){
if(cur0){
this.statubar.setText(没有找到!);
}else{
int i=this.text.getText().lastIndexOf(str);
if(i=0){
this.text.setSelectionStart(i);
this.text.setSelectionEnd(i+str.length());
this.statubar.setText(已经在:+i+ 位置找到!);
}else{
upFindStr(str,--cur);
}
}
}
void replaceStr(String findStr,String replaceStr,int cur,int end){
if(curend){
this.statubar.setText(没有找到!);
}else{
int i=this.text.getText().indexOf(findStr);
if(i0){
this.text.setSelectionStart(i);
this.text.setSelectionEnd(i+findStr.length());
this.text.replaceRange(replaceStr,this.text.getSelectionStart(),this.text.getSelectionEnd());
}else{
replaceStr(findStr,replaceStr,++cur,end);
}
}
}
/*------------------------------------------------
*
* main
*
*-----------------------------------------------
*/
public static void main(String[] args){
Jsb jsb1=new Jsb();
}
}
/************************************************************
///////////////////////// Event class ///////////////////////
**************************************************************/
class Jsb_frame_closingAdapter extends java.awt.event.WindowAdapter{
Jsb adaptee;
Jsb_frame_closingAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void windowClosing(WindowListener e){
adaptee.frame_windowclose_windowClosing(e);
}
}
///////////////////////////////////////////////////////////
class Jsb_text_mouseAdapter extends java.awt.event.MouseAdapter{
Jsb adaptee;
Jsb_text_mouseAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void mouseClicked(MouseEvent e){
adaptee.text_mouseClicked(e);
}
}
class Jsb_text_ancestorAdapter implements javax.swing.event.AncestorListener{
Jsb adaptee;
Jsb_text_ancestorAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void ancestorAdded(AncestorEvent e){
adaptee.text_ancestorAdded(e);
}
public void ancestorRemoved(AncestorEvent e){
}
public void ancestorMoved(AncestorEvent e){
}
}
class Jsb_text_caretAdapter implements javax.swing.event.CaretListener{
Jsb adaptee;
Jsb_text_caretAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void caretUpdate(CaretEvent e){
adaptee.text_caretUpdate(e);
}
}
///////////////////////////////////////////////////////////
class File_open_actionAdapter implements java.awt.event.ActionListener{
Jsb adaptee;
File_open_actionAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.File_open_actionPerformed(e);
}
}
class File_new_actionAdapter implements java.awt.event.ActionListener{
Jsb adaptee;
File_new_actionAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.File_new_actionPerformed(e);
}
}
class File_save_actionAdapter implements java.awt.event.ActionListener{
Jsb adaptee;
File_save_actionAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.File_save_actionPerformed(e);
}
}
class File_saveas_actionAdapter implements java.awt.event.ActionListener{
Jsb adaptee;
File_saveas_actionAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.File_saveas_actionPerformed(e);
}
}
class File_quite_actionAdapter implements java.awt.event.ActionListener{
Jsb adaptee;
File_quite_actionAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.File_quite_actionPerformed(e);
}
}
//////////////////////////////////////////////////////////////
class Edit_undo_actionAdapter implements java.awt.event.ActionListener{
Jsb adaptee;
Edit_undo_actionAdapter(Jsb adaptee){
this.adaptee=adaptee;
}
public void actionPerformed(ActionEvent e){
adaptee.Edit_undo_acti
如何用JAVA设计程序窗口
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FrameTest {
private JFrame jf;
private JButton yellow,blue,green;
private JPanel panel1;
public FrameTest(){
jf = new JFrame("Frame");
yellow = new JButton("yellow");
blue = new JButton("blue");
green = new JButton("green");
panel1 = new JPanel();
panel1.setLayout(new FlowLayout());
jf.add(panel1,BorderLayout.CENTER);
jf.setVisible(true);
jf.setSize(500,600);
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
blue.setForeground(Color.blue);
panel1.add(blue);
blue.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
panel1.setBackground(Color.blue);
}
});
yellow.setForeground(Color.yellow);
panel1.add(yellow);
yellow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
panel1.setBackground(Color.yellow);
}
});
green.setForeground(Color.green);
panel1.add(green);
green.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
panel1.setBackground(Color.green);
}
});
}
public static void main(String args[]){
FrameTest ft = new FrameTest();
}
}
如何在windows命令行窗口运行Java程序
1、首先,运行Java程序,需要安装好jdk
2、在windows命令行窗口输入java和javac验证环境变量path是否配置好
3、编写好正确的java小程序
4、在windows命令行进入到程序所在路径下,javac编译,会在原有程序下新生成一个.class文件,java运行.class文件,就可以成功运行Java程序啦
java窗口程序制作
不知道你要连什么数据库的说.
硬性规定要用数据库的么,要是要的话,你可以自己改改下面的代码的说.
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame {
/**
* serialVersionUID.
*/
private static final long serialVersionUID = 158951615131406887L;
private JLabel userName = new JLabel("用户名:");
private JTextField userNameField = new JTextField(10);
private JLabel password = new JLabel("密码:");
private JPasswordField passwordField = new JPasswordField(10);
private JButton loginButton = new JButton("登录");
private JButton register = new JButton("注册");
private JPanel panel = new JPanel();
public LoginFrame(String name, Point p) {
super(name);
setLocation(p);
GridBagLayout layout = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
panel.setLayout(layout);
constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
layout.setConstraints(userName, constraints);
constraints.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(userNameField, constraints);
constraints.gridwidth = GridBagConstraints.RELATIVE;
layout.setConstraints(password, constraints);
constraints.gridwidth = GridBagConstraints.REMAINDER;
layout.setConstraints(passwordField, constraints);
panel.add(userName);
panel.add(userNameField);
panel.add(password);
panel.add(passwordField);
panel.add(loginButton);
panel.add(register);
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String username = userNameField.getText();
char[] passwordStrAry = passwordField.getPassword();
String password = passwordStrAry != null ? new String(
passwordStrAry) : null;
if (username == null || password == null || "".equals(username)
|| "".equals(password)) {
JOptionPane.showMessageDialog(null, "密码和用户名不能为空", "注意",
JOptionPane.ERROR_MESSAGE);
if (username == null || "".equals(username))
userNameField.grabFocus();
else
passwordField.grabFocus();
return;
}
boolean checkResult = UserManager
.loginCheck(username, password);
if (!checkResult) {
JOptionPane.showMessageDialog(null, "密码或用户名不正确", "注意",
JOptionPane.ERROR_MESSAGE);
} else {
new MessageFrame("登录成功,欢迎光临!", getLocation());
dispose();
}
}
});
register.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new RegisterFrame("注册界面", getLocation());
dispose();
}
});
setLayout(new FlowLayout());
add(panel);
setSize(250, 130);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}这个是登录界面的代码的说
窗口程序java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于窗口程序Java、窗口程序java的信息别忘了在本站进行查找喔。