java程序出错

不知道哪里出错了packageadalaxi;importjava.awt.BorderLayout;importjava.awt.EventQueue;importja... 不知道哪里出错了
package adalaxi;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

public class Ked extends JFrame{
private JPanel contentPane;
public static void main(String[] args){
EventQueue.invokeLater(new Runnable(){
public void run(){
try{
Ked frame=new Ked();
frame.setVisible(true);
}catch(Exception e){
e.printStackTrace();
}
}
});
}
public Ked(){
setTitle("aaaaa");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,450,300);
contentPane=new JPanel();
contentPane.setBorder(new EmptyBorder(5,5,5,5));
contentPane.setLayout(new BorderLayout(0,0));
setContentPane(contentPane);
JScrollPane scrollPane=new JScrollPane();
contentPane.add(scrollPane,BorderLayout.CENTER);
final JTextArea textArea=new JTextArea();
textArea.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent e){
String keyText=KeyEvent.getKeyText(e.getKeyCode());
if(e.isActionKey()){
System.out.println(keyText);
}else{
System.out.println("feidongzuojian");
int keyCode=e.getKeyCode();
switch (keyCode){
case KeyEvent.VK_CONTROL:
System.out.println(",CON");
break;
switch (keyCode){
case KeyEvent.VK_ALT:
System.out.println(",ALT");
break;
switch (keyCode){
case KeyEvent.VK_SHIFT:
System.out.println(",SHI");
break;
}
System.out.println();
}
}
public void keyTyped(KeyEvent e){
System.out.println("konkaiwa"+e.getKeyChar());
}
public void keyReleased(KeyEvent e) {
String keyText=KeyEvent.getKeyText(e.getKeyCode());
System.out.println("hanaxidanowa"+keyText);
}
});
textArea.setFont(new Font("微软雅黑",Font.PLAIN,20));
scrollPane.setViewportView(textArea);

})
}

}
展开
 我来答
lifetime217
2014-08-16 · 超过29用户采纳过TA的回答
知道答主
回答量:43
采纳率:0%
帮助的人:32.7万
展开全部
代码给你进行了修改,主要是你拿switch case用的完全不忍直视。你看看还有什么问题吧。
public class Ked extends JFrame {
private JPanel contentPane;

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Ked frame = new Ked();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

public Ked() {
setTitle("aaaaa");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JScrollPane scrollPane = new JScrollPane();
contentPane.add(scrollPane, BorderLayout.CENTER);
final JTextArea textArea = new JTextArea();
textArea.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
String keyText = KeyEvent.getKeyText(e.getKeyCode());
if (e.isActionKey()) {
System.out.println(keyText);
} else {
System.out.println("feidongzuojian");
int keyCode = e.getKeyCode();
switch (keyCode) {
case KeyEvent.VK_CONTROL:
System.out.println(",CON");
break;
case KeyEvent.VK_ALT:
System.out.println(",ALT");
break;
case KeyEvent.VK_SHIFT:
System.out.println(",SHI");
break;
default:
System.out.println();
}
}
}

public void keyTyped(KeyEvent e) {
System.out.println("konkaiwa" + e.getKeyChar());
}

public void keyReleased(KeyEvent e) {
String keyText = KeyEvent.getKeyText(e.getKeyCode());
System.out.println("hanaxidanowa" + keyText);
}
});
textArea.setFont(new Font("微软雅黑", Font.PLAIN, 20));
scrollPane.setViewportView(textArea);
}
}
鼓浅深3837
2014-08-16 · TA获得超过120个赞
知道答主
回答量:117
采纳率:0%
帮助的人:150万
展开全部
你的思路有点乱,我帮你把程序调整了一下,还望采纳
public class Book {

private String name;
public String getName1(){
int id = 0;
setName("Java");
return id + this.name;
}
private void setName(String name){
this.name = name;
}
public Book getName(){
return this;
}
public static void main(String[] args) {
Book a=new Book();
System.out.println(a.getName());
System.out.println(a.getName1());
}

}
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
www6wzk
2014-08-16
知道答主
回答量:28
采纳率:0%
帮助的人:11.6万
展开全部
你的switch语句写错了吧
package adalaxi;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

public class Ked extends JFrame{
private JPanel contentPane;
public static void main(String[] args){
EventQueue.invokeLater(new Runnable(){
public void run(){
try{
Ked frame=new Ked();
frame.setVisible(true);
}catch(Exception e){
e.printStackTrace();
}
}
});
}
public Ked(){
setTitle("aaaaa");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100,100,450,300);
contentPane=new JPanel();
contentPane.setBorder(new EmptyBorder(5,5,5,5));
contentPane.setLayout(new BorderLayout(0,0));
setContentPane(contentPane);
JScrollPane scrollPane=new JScrollPane();
contentPane.add(scrollPane,BorderLayout.CENTER);
final JTextArea textArea=new JTextArea();
textArea.addKeyListener(new KeyListener(){

public void keyPressed(KeyEvent e) {
String keyText=KeyEvent.getKeyText(e.getKeyCode());
if(e.isActionKey()){
System.out.println(keyText);
}else{
System.out.println("feidongzuojian");
int keyCode=e.getKeyCode();
switch (keyCode){
case KeyEvent.VK_CONTROL:
System.out.println(",CON");
break;
case KeyEvent.VK_ALT:
System.out.println(",ALT");
break;
case KeyEvent.VK_SHIFT:
System.out.println(",SHI");
break;
}
System.out.println();
}
}

public void keyReleased(KeyEvent e) {
System.out.println("konkaiwa"+e.getKeyChar());
}

public void keyTyped(KeyEvent e) {
String keyText=KeyEvent.getKeyText(e.getKeyCode());
System.out.println("hanaxidanowa"+keyText);
}

});
textArea.setFont(new Font("微软雅黑",Font.PLAIN,20));
scrollPane.setViewportView(textArea);
}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式