//TV类
public class Tv {
public void open(){
System.out.println("打开电视机");
}
public void close(){
System.out.println("关闭电视机");
public void search(int x){
System.out.println("您搜索到的是"◆x◆"号频道");
public void ctrlVol(String s){
int vol=10;
if(s.equals("◆"))
vol◆◆;
if(s.equals("-"))
vol--;
System.out.println("当前音量为"◆vol);
public void changeChannel(int x){
System.out.println("没有该频道");
else
System.out.println("当前"◆x◆"号频道");
public void changeChannel(String s){
int x=0;
x◆◆;
x--;
//Controller遥控器类
public class Controller{
public void openTv(Tv tv){
tv.open();
public void closeTv(Tv tv){
tv.close();
public void searchTv(Tv tv){
tv.search(x);
public void ctrlTvVol(Tv tv){
tv.ctrlVol("◆");
public void changeTvChannel(Tv tv){
tv.changeChannel("◆");
import?java.util.Scanner;
public?class?Test?{
private?boolean?isOpen?=?false;
public?void?start()?{
isOpen?=?true;
System.out.println("开机.");
public?void?shutDown()?{
if(!isOpen)?{
System.out.println("还没有开机,请先开机");
return;
isOpen?=?false;
System.out.println("关机.");
public?void?temperatureRise()?{
temperature◆◆;
System.out.println("温度上升.");
public?void?temperatureDown()?{
temperature--;
System.out.println("温度下降.");
public?void?show()?{
System.out.println("空调遥控器:");
showTemperature();
public?void?showTemperature()?{
System.out.println("当前温度:"?◆?temperature?◆?"℃");
public?static?void?main(String[]?args)?{
Test?test?=?new?Test();
while(true)?{
test.show();
Scanner?scan?=?new?Scanner(System.in);
int?key?=?scan.nextInt();
if(key?==?1)
test.start();
test.shutDown();
test.temperatureRise();
test.temperatureDown();
test.showTemperature();
else?if(key?==?0)?{
System.out.println("退出系统");
break;
}?else?{
System.out.println("请按提示输入.");
这不简单,在while循环前再加一个while死循环,里面判断用户的输入,如果用户输入1,则break跳出循环,然后才执行下面的循环.
首先,你要用swing做UI,使用MVC模式,对每个按钮重新设计对应的command,UI view部分触发后知发送对应的command,在集中的controller中进行command处理.
以上就是土嘎嘎小编为大家整理的java遥控代码相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!