永发信息网

java程序有二个错误,实在是找不到原因,望高手帮忙看看,谢谢了!

答案:6  悬赏:60  手机版
解决时间 2021-02-03 22:53
  • 提问者网友:我是女神我骄傲
  • 2021-02-02 23:10
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class junber8 extends JFrame{

private JSplitPane panev,paneh;
private JScrollPane scropane;
private JPanel pleft;
private JPanel pright;
private JTextArea textarea;
private JLabel label;
private JTextField field;
private JButton button1,button2;

public junber8(){
super("聊天室");

textarea=new JTextArea();
textarea.setEditable(false);
scropane=new JScrollPane(textarea);
pleft=new JPanel();
label=new JLabel("输入");
field=new JTextField(20);
button1=new JButton("发送");

pleft.add(label);
pleft.add(field);
pleft.add(button1);

pright=new JPanel();
button2=new JButton("俊ber");

pright.add(button2);

panev=new JSplitPane(JScrollPane.VERTICAL_SPLIT,scropane,pleft);
panev.setDividerLocation(320);
paneh=new JSplitPane(JScrollPane.HORIZONTAL_SPLIT,panev,pright);
paneh.setDividerLocation(350);
this.add(paneh);

this.setSize(500,400);
this.setLocation(300,300);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String args[]){
junber8 junber=new junber8();
junber.setVisible(true);
}
}
最佳答案
  • 五星知识达人网友:第幾種人
  • 2021-02-03 00:23
panev=new JSplitPane(JSplitPane.VERTICAL_SPLIT,scropane,pleft);
panev.setDividerLocation(320);
paneh=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panev,pright);
paneh.setDividerLocation(350);
this.add(paneh);

修改你中间的一段代码。
你的构造函数写错了。
JSplitPane
public JSplitPane(int newOrientation,
Component newLeftComponent,
Component newRightComponent)创建一个具有指定方向和不连续重绘的指定组件的新 JSplitPane。

参数:
newOrientation - JSplitPane.HORIZONTAL_SPLIT 或 JSplitPane.VERTICAL_SPLIT
newLeftComponent - 将出现在水平分隔窗格的左边或者垂直分隔窗格的顶部的 Component
newRightComponent - 将出现在水平分隔窗格的右边或者垂直分隔窗格的底部的 Component
全部回答
  • 1楼网友:洎扰庸人
  • 2021-02-03 04:25
额,麻烦把异常贴出来,让我们看看是编译期出错还是解释期出错。
  • 2楼网友:迷人又混蛋
  • 2021-02-03 04:06
panev=new JSplitPane(JScrollPane.VERTICAL_SPLIT,scropane,pleft); paneh=new JSplitPane(JScrollPane.HORIZONTAL_SPLIT,panev,pright); 只要把这两行的JScrollPane改成JSplitPane就可以了,修改后如下: panev=new JSplitPane(JSplitPane.VERTICAL_SPLIT,scropane,pleft); paneh=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panev,pright); 你用的什么开发工具啊,要是用Eclipse的话,直接按CTRL+1就可以有自动提示,错误很容易解决的,同时建议你下一个JDK_API_1_6_zh_CN.CHM,在百度上搜索Java API下载就可以了,可以轻松查看各类的接口,这样就不会再犯这样的错误了。
  • 3楼网友:持酒劝斜阳
  • 2021-02-03 03:05
panev=new JSplitPane(JScrollPane.VERTICAL_SPLIT,scropane,pleft); 这个错了啊,应该写成: panev=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scropane,pleft); 呵呵,是个小错误,要细心点啊。
  • 4楼网友:毛毛
  • 2021-02-03 02:36
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class junber8 extends JFrame{ private JSplitPane panev,paneh; private JScrollPane scropane; private JPanel pleft; private JPanel pright; private JTextArea textarea; private JLabel label; private JTextField field; private JButton button1,button2; public junber8(){ super("聊天室"); textarea=new JTextArea(); textarea.setEditable(false); scropane=new JScrollPane(textarea); pleft=new JPanel(); label=new JLabel("输入"); field=new JTextField(20); button1=new JButton("发送"); pleft.add(label); pleft.add(field); pleft.add(button1); pright=new JPanel(); button2=new JButton("俊ber"); pright.add(button2); panev=new JSplitPane(JSplitPane.VERTICAL_SPLIT,scropane,pleft); panev.setDividerLocation(320); paneh=new JSplitPane(JSplitPane.VERTICAL_SPLIT,panev,pright); paneh.setDividerLocation(350); this.add(paneh); this.setSize(500,400); this.setLocation(300,300); this.setResizable(false); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String args[]){ junber8 junber=new junber8(); junber.setVisible(true); } } 修改后的代码
  • 5楼网友:时间的尘埃
  • 2021-02-03 01:58
paneh=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,panev,pright); 是JSplitPane.HORIZONTAL_SPLIT 不是JScrollPane.HORIZONTAL_SPLIT
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯