闲着没事,网上找了许多资料自学JAVA不久,想尝试自己做个什么项目.但是碰到个小小的困难,就是面板布局的时候,其中的表单超过了显示的范围,想在其中加JScrollPane的滚条效果.我显示用GridBagConstraints()布局,但是表单的位置设置不好(是水平不佳吧..)..后来用setBounds(X,X,X,X)定义表单位置,却没有了滚条的效果.又找不到解决的方法.想寻求下帮助,谢谢!(另外..有个较笨的错误,首页上有个txt表单,不知怎么去掉..知道是哪写错了漏了帮个忙,谢谢~THANKS!)
代码如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Container.*;
import java.sql.*;
public class Sysobj extends JApplet
{
//参数定义
int n,m;
int id;
//窗口参数
JPanel paneltop;
JPanel panelbottom;
JPanel panelEnter;
JPanel panelEnter1;
JPanel panelLogin;
JPanel panelShow;
//登陆页表单参数
JLabel UserID;
JLabel PassWord;
JLabel Login;
JLabel GetPassWord;
JTextField TextUserID;
JPasswordField TextPassWord;
JButton Enter;
//登陆后显示的表单参数
JButton lbttop1;
JButton lbttop2;
JButton lbttop3;
JButton lbttop4;
JButton lbttop5;
JButton lbttop6;
//1设置
JButton jbtset1;
JButton jbtset2;
//2基本信息
JButton jbtmsg1;
JButton jbtmsg2;
JButton jbtmsg3;
//3海运出口
JButton jbtso1;
JButton jbtso2;
JButton jbtso3;
JButton jbtso4;
JButton jbtso5;
JButton jbtso6;
JButton jbtso7;
JComboBox comboselect;
JTextField textselect;
JButton jbtguolv1;
JLabel lbview1;
JComboBox comboyear;
JComboBox combomonth;
JLabel lbseao1;
JLabel lbseao2;
JLabel lbseao3;
JLabel lbseao4;
JLabel lbseao5;
JLabel lbseao6;
JLabel lbseao7;
JLabel lbseao8;
JLabel lbseao9;
JLabel lbseao10;
JLabel lbseao11;
JLabel lbseao12;
JLabel lbseao13;
JLabel lbseao14;
JLabel lbseao15;
JLabel lbseao16;
JLabel lbseao17;
JLabel lbseao18;
JScrollPane jsp;
//4海运进口
JButton jbtsi1;
JButton jbtsi2;
JButton jbtsi3;
JButton jbtsi4;
JButton jbtsi5;
JButton jbtsi6;
//5财务管理
JButton jbtcw1;
JButton jbtcw2;
//5-1出口
JButton jbtcwo1;
JButton jbtcwo2;
JButton jbtcwo3;
JButton jbtcwo4;
JButton jbtcwo5;
//5-2进口
JButton jbtcwi1;
JButton jbtcwi2;
JButton jbtcwi3;
//6发票管理
JButton jbtfp1;
JButton jbtfp2;
JLabel Speace;
//颜色参数定义
Color a1=new Color(128,219,239);
Color a2=new Color(109,181,255);
//数据库连接参数定义
Connection con;
ResultSet result;
Statement stat;
public void init()
{
getContentPane().setLayout(null);
getContentPane().setBackground(a1);
getAppletContext().showStatus("只是试验而已");
/*try
{
//数据库连接
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:mysql","sa","1111");
stat=con.createStatement();
}
//数据库连接错误返回信息
catch(Exception exception)
{
System.out.print("Error encountered while entering date in the database: " + exception);
}*/
//加载显示窗口
//主页顶上的图标
paneltop();
//登陆主页界面
panelEnter();
//登陆后的主窗口
panelShow();
}
//顶上图表窗口
public void paneltop()
{
JLabel top;
JLabel miqi1;
paneltop = new JPanel();
getContentPane().add(paneltop);
paneltop.setBackground(a1);
paneltop.setLayout(null);
paneltop.setBounds(0,0,800,80);
ImageIcon miqipic1 = new ImageIcon("");
miqi1 = new JLabel(miqipic1);
miqi1.setBounds(0,8,800,80);
paneltop.add(miqi1);
}
//登陆界面
public void panelEnter()
{
a1=new Color(128,219,239);
panelEnter = new JPanel();
panelEnter1 = new JPanel();
getContentPane().add(panelEnter);
panelEnter.setLayout(null);
panelEnter.setBounds(0,80,800,440);
panelEnter.setBackground(a1);
panelEnter.add(panelEnter1);
panelEnter1.setBounds(0,80,800,300);
panelEnter1.setBackground(a1);
GridBagLayout gl;
GridBagConstraints gbc;
gl = new GridBagLayout();
gbc = new GridBagConstraints();
panelEnter1.setLayout(gl);
UserID = new JLabel("用户名:");
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 1;
gbc.gridy = 1;
gl.setConstraints(UserID,gbc);
panelEnter1.add(UserID);
UserID.setForeground(Color.blue);
TextUserID = new JTextField(8);
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 2;
gbc.gridy = 1;
gl.setConstraints(TextUserID,gbc);
panelEnter1.add(TextUserID);
PassWord = new JLabel("密 码:");
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 1;
gbc.gridy = 2;
gl.setConstraints(PassWord,gbc);
panelEnter1.add(PassWord);
PassWord.setForeground(Color.blue);
TextPassWord = new JPasswordField(8);
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 2;
gbc.gridy = 2;
gl.setConstraints(TextPassWord,gbc);
panelEnter1.add(TextPassWord);
GetPassWord = new JLabel("找回密码");
gbc.anchor = GridBagConstraints.CENTER;
gbc.gridx = 3;
gbc.gridy = 1;
gl.setConstraints(GetPassWord,gbc);
panelEnter1.add(GetPassWord);
GetPassWord.setForeground(Color.blue);
Enter = new JButton("登陆");
gbc.anchor = GridBagConstraints.WEST;
gbc.gridx = 3;
gbc.gridy = 2;
gl.setConstraints(Enter,gbc);
panelEnter1.add(Enter);
Enter.setBackground(Color.green);
validateAction validateButton = new validateAction();
Enter.addActionListener(validateButton);
}
//登陆事件
class validateAction implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Object obj = evt.getSource();
//按登陆按键所触发的事件
if (obj == Enter)
{/*
String UserID = TextUserID.getText();
if (UserID.length() == 0)
{
JOptionPane.showMessageDialog(null,"用户名不能为空!",
"Error message",JOptionPane.WARNING_MESSAGE);
return;
}
char[] passWord = TextPassWord.getPassword();
if (passWord.length == 0)
{
JOptionPane.showMessageDialog(null,"密码不能为空!",
"Error message",JOptionPane.WARNING_MESSAGE);
return;
}
try
{
int ok = 0;
//登陆数据查询验证
Statement stat=con.createStatement();
ResultSet result = stat.executeQuery("Select * from cus");
while (result.next())
{
if (TextUserID.getText().equals(result.getString(1).trim()))//验证第1列数据(用户名)
{
if (String.valueOf(TextPassWord.getPassword()).equals(result.getString(2).trim()))//验证第2列数据(密码)
{
ok = 1;
break;
}
else
{
JOptionPane.showMessageDialog(null,"您输入的密码不正确!",
"Error message",JOptionPane.WARNING_MESSAGE);
stat.close();
return;
}
}
else
continue;
}
if(ok != 1)
{
JOptionPane.showMessageDialog(null,"您输入的用户名不存在!",
"Error message",JOptionPane.WARNING_MESSAGE);
stat.close();
return;
}
stat.close();
}
//访问数据库错误的返回信息
catch(Exception exception)
{
JOptionPane.showMessageDialog(null,"Error 访问数据库错误: " + exception,
"Error message",JOptionPane.WARNING_MESSAGE);
}*/
panelEnter.setVisible(false);
remove(panelEnter);
panelEnter1.setVisible(false);
remove(panelEnter1);
panelShow.setVisible(true);
jsp.setVisible(true);
getContentPane().add(jsp);
}
}
}
JScrollPane滚条的问题[请求帮助]