简体   繁体   English

导入软件包时出错

[英]error when importing packages

package textar;
import java.awt.*;
import javax.swing.*;
public class textarea extends JInternalFrame
{
     public static JTextArea txtaMessage;
     textarea() {
         super("Private Cloud Environment",true,false,true,true);       
         txtaMessage=new JTextArea();
         JScrollPane  scrollPane=newJScrollPane(txtaMessage,
                                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
         txtaMessage.setFont(new Font("Serif", Font.BOLD, 16));
         txtaMessage.setEditable(false);
         getContentPane().setLayout(new GridLayout(1,1));
         getContentPane().add(scrollPane);
         setSize(650,650);
         setVisible(true);
     }
}

So above is my block of code which has to b called in the followin program 所以上面是我的代码块,必须在后续程序中调用b

import package textar.*;
public Main()
{                   
    //creating object for textarea InternalFrame
    textarea objtxta=new textarea();
    addFrame(objtxta);
}

but when compiling 但是在编译时

  import package textar.*;
  ^
  1 error

  "error: identifier expected" pops out !! 

I hav skipped other parts of d program because they have nothing to do with the package. 我跳过了d程序的其他部分,因为它们与程序包无关。

Help me out please !! 请帮帮我! And Thanks in advance !! 并预先感谢!

The use of the package keyword is invalid in import statement here. 在此处的import语句中,使用package关键字无效。 You can use: 您可以使用:

import textar.*;

Your calling class does not appear to have the class declared: 您的调用类似乎没有声明该类:

import textar.*;

public class Main {

   public Main() {                   
    //creating object for textarea InternalFrame
    textarea objtxta=new textarea();
    addFrame(objtxta);
   }
   ...

Also there should be spaces between the keywords in the declaration of JScrollPane in the textarea class: textarea类的JScrollPane声明中,关键字之间也应该有空格:

JScrollPane scrollPane = new JScrollPane(txtaMessage,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM