public void setReadOnly

本文提供了一个Java类的示例代码,展示了如何设置和获取成员属性的方法,包括设置只读状态、请求ID以及数据库对象。此外,还介绍了一个继承自基类的MemberAction类,实现了ModelDriven和Preparable接口,并在prepare方法中根据请求ID的不同加载新的成员实例或从数据库中获取现有成员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 public void setReadOnly(boolean readOnly){

  this.readOnly = readOnly;

  log.debug("setting readOnly to "+readOnly);

  }

  public long getRequestId(){

  return requestId;

  }

  public void setRequestId(long requestId){

  this.requestId = requestId;

  }

  public void setDb(DB db){

  this.db = db;

  }

  public boolean isReadOnly(){

  return readOnly;

  }

  public abstract Object getModel();

  }

  public class MemberAction extends BaseAction implements ModelDriven,Preparable {

  private Member model;

  public Member getModel(){

  return model;

  }

  public void prepare() throws Exception{

  if(getRequestId() == 0){

  model = new Member();

  }else{

  model = (Member) db.get(getRequestId);

  }

  }

  }

#ifndef DIALOG_H #define DIALOG_H #include <QDialog> QT_BEGIN_NAMESPACE namespace Ui { class Dialog; } QT_END_NAMESPACE class QTimer; class Dialog : public QDialog { Q_OBJECT public: Dialog(QWidget *parent = nullptr); ~Dialog(); private slots: void onTime(); void on_pushButton_start_01_clicked(); void on_pushButton_end_01_clicked(); void on_pushButton_start_02_clicked(); void on_pushButton_end_02_clicked(); void on_pushButton_start_03_clicked(); void on_pushButton_end_03_clicked(); private: Ui::Dialog *ui; QTimer *timer_ = nullptr; bool time_1 = false; bool time_2 = false; bool time_3 = false; }; #endif // DIALOG_H #include "dialog.h" #include "ui_dialog.h" #include <QDateTime> #include <QTimer> #include <QMessageBox> #include <QDebug> Dialog::Dialog(QWidget *parent) : QDialog(parent) , ui(new Ui::Dialog) { ui->setupUi(this); timer_ = new QTimer (this); connect(timer_,&QTimer::timeout,this,&Dialog::onTime); timer_->start(1000); } Dialog::~Dialog() { delete ui; } void Dialog::onTime(){ auto time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); qint64 current_ms = QDateTime::currentDateTime().currentMSecsSinceEpoch(); qint64 ms_1 = ui->dateTimeEdit_clock01->dateTime().toMSecsSinceEpoch(); qint64 ms_2 = ui->dateTimeEdit_clock_02->dateTime().toMSecsSinceEpoch(); qint64 ms_3 = ui->dateTimeEdit_clock_03->dateTime().toMSecsSinceEpoch(); qDebug() << "time" << ms_1; qDebug() << "time2" <<ms_2; qDebug() << "time3" <<ms_3; qDebug() << "current_ms" << current_ms; if(current_ms >= ms_1 && time_1 == false){ time_1 = true; QMessageBox::information(this,"闹钟1","闹钟1的时间到了"); } if(current_ms >= ms_2 && time_2 == false){ time_2 = true; QMessageBox::information(this,"闹钟2","闹钟2的时间到了"); } if(current_ms >= ms_3 && time_3 == false){ time_3 = true; QMessageBox::information(this,"闹钟3","闹钟3的时间到了"); } ui->lcdNumber_clock->display(time); } void Dialog::on_pushButton_start_01_clicked() { ui->dateTimeEdit_clock01->setReadOnly(true); time_1 = false; } void Dialog::on_pushButton_end_01_clicked() { QMessageBox box(QMessageBox::Warning,"Warning","是否要重新设闹钟",QMessageBox::Yes|QMessageBox::No); int ret = box.exec(); if(ret == QMessageBox::Yes){ ui->dateTimeEdit_clock01->setReadOnly(false); ui->dateTimeEdit_clock01->clear(); } } void Dialog::on_pushButton_start_02_clicked() { } void Dialog::on_pushButton_end_02_clicked() { } void Dialog::on_pushButton_start_03_clicked() { } void Dialog::on_pushButton_end_03_clicked() { } 怎么通过按钮start和end控制闹钟的开始与停止,要求显示当前的时间不修改,只修改的是显示闹钟的界面
最新发布
07-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值