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);
})
}
} 展开
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);
})
}
} 展开
展开全部
代码给你进行了修改,主要是你拿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);
}
}
展开全部
你的思路有点乱,我帮你把程序调整了一下,还望采纳
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());
}
}
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());
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的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);
}
}
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);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询